首页 文章

React路由器仅在按下后退按钮时才有效

提问于
浏览
0

我有一个非常简单的反应路由器设置,无法正常工作 . 当我导航URL栏更改但反应路由器永远不会更新页面 . 如果我重新加载页面,则在初始加载时呈现正确的路由 . 如果我按后退/前进按钮,路由器之间的路由器正确导航 . 即使后退/前进正在使用反应路由器点击指向页面的链接,我可以通过后退/前进到达仍然无效 .

我的路线

import { Router, Route, IndexRoute, browserHistory } from 'react-router'
import AppContainer from './components/react/app_container.jsx'
import Signup from './components/react/login_and_signup/signup.jsx'
import SplashPage from './components/react/splash_page/splash_page.jsx'
export const routes = (
    <Router history={browserHistory}>
        <Route path="/" component={AppContainer}>
            <IndexRoute component={SplashPage} />
            <Route path="signup" component={Signup} />
        </Route>
    </Router>
);

引导我的应用程序

import ReactDOM from 'react-dom';
import {routes} from '../imports/client/routes'

ReactDOM.render(routes, document.getElementById('app'));

我的AppContainer

import React from 'react';

let AppContainer = React.createClass({
    componentWillReceiveProps(nextProps){
      console.log("next props? ", nextProps);
    },
    render(){
        return <div>{this.props.children}</div>
    }
});

export default AppContainer;

在我的启动页面中:

<Link to="/signup">
   signup
</Link>

这是我得到的行为:

  • 在/ URL重新加载页面,启动页面加载

  • 单击注册链接,URL更改为/ signup但未呈现注册组件,并且不输出componentWillReceiveProps中的console.log

  • 在/注册时重新加载页面,并正确呈现注册组件

  • 按后退按钮,正确渲染启动页面组件,并从componentWillReceiveProps输出道具

  • 此时前进和后退按钮正常工作

  • 点击启动页面上的注册链接,URL更改为/注册但没有任何反应

据我所知,我已经正确配置了所有内容但反应路由器默默地失败,除了后退/前进按钮 .

我在React 15.0.1和React Router 2.4.1上 .

1 回答

  • 1

    流星程序包Iron Router包含在我的项目中,与React Router冲突 . 删除Iron Router解决了这个问题 .

相关问题