react vr的导航一直很少有人去做,场景的切换一般都采用简单的state管理,也就是点击vrbutton改变state的值,切换新的场景,同时我们也可以用react上的路由来进行路由的导航,此处介绍react-router在react-vr中的应用。
react-router在react-vr中的应用:https://github.com/LiuC520/react-vr-router
直接在项目中安装react-router,
npm install --save react-router
然后在你的文件中引用:
import { MemoryRouter as Router, Redirect, Route, Switch } from 'react-router';
然后:
import React,{Component} from 'react';
import {
AppRegistry,
asset,
Pano,
Text,
View,
} from 'react-vr';
import { MemoryRouter as Router, Redirect, Route, Switch } from 'react-router';
import TS1 from './src/test'
import TS2 from './src/test_1'
class Example extends Component{
render(){
return(
<Router>
<View>
<Route exact path='/' component={TS1}/>
<Route exact path='/test_1' component={TS2}/>
<Route exact path='/test' component={TS1}/>
</View>
</Router>
)
}
}
AppRegistry.registerComponent('Example', () => Example);
网友评论