Guy*_*Guy 10 react-router react-360
我正在试图找出如何使用React VR插入React路由器.
首先,我应该使用react-router dom/ native?目前尚不清楚,因为React VR构建在React Native之上,但在浏览器中运行.
这是我遇到问题的代码.
import React from 'react';
import { AppRegistry } from 'react-vr';
import {
BrowserRouter as Router,
Route
} from 'react-router-dom'
import Landing from './components/Landing';
import Video from './components/Video';
export default class WelcomeToVR extends React.Component {
render() {
return (
<Router>
<Route exact path={'/vr/'} component={Landing} />
<Route exact path={'/vr/video/'} component={Video} />
</Router>
);
}
};
AppRegistry.registerComponent('WelcomeToVR', () => WelcomeToVR);
Run Code Online (Sandbox Code Playgroud)
我根据remydib使用 React-router 4.1.2提到的 Ryan Florence 视频提供了这个解决方案。
在主应用程序组件中:
import { MemoryRouter, Redirect, Route, Switch } from 'react-router';
...
<MemoryRouter>
...
</MemoryRouter>
Run Code Online (Sandbox Code Playgroud)
在使用VrButton的组件中:
export class NavBtn extends React.Component {
static contextTypes = {
router: React.PropTypes.object.isRequired,
};
render() {
const { to } = this.props;
const onClick = () => this.context.router.history.push(to);
return (
<VrButton onClick={onClick}>
...
</VrButton>
);
}
}
Run Code Online (Sandbox Code Playgroud)
npm中有react-router-vr包,但它看起来只是占位符。遗憾的是,目前不支持浏览器 URL。
| 归档时间: |
|
| 查看次数: |
694 次 |
| 最近记录: |