加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-router – 如何使用React VR与React VR进行反应?

发布时间:2020-12-15 20:47:24 所属栏目:百科 来源:网络整理
导读:我正在试图找出如何使用React VR插入React路由器. 首先,我应该使用react-router dom / native吗?目前尚不清楚,因为React VR构建在React Native之上,但在浏览器中运行. 这是我遇到问题的代码. import React from 'react';import { AppRegistry } from 'react
我正在试图找出如何使用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);

在/ vr /上打开浏览器时,上面的代码返回以下错误:

我使用react-router 4.1.2来提供基于 remydib提到的Ryan Florence视频的解决方案.

在主应用程序组件中:

import { MemoryRouter,Redirect,Route,Switch } from 'react-router';

...

    <MemoryRouter>
    ...
    </MemoryRouter>

在使用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>
        );
    }
}

在npm中有react-router-vr包,但它看起来只是占位符.遗憾的是,此刻不支持浏览器URL.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读