react-router始终路由到'NotFoundRoute'

时间:2015-02-20 05:39:15

标签: reactjs react-router

我已经做了几个月的反应。爱它。刚刚拿起反应路由器。它看起来很棒,很简单,但我的路线并没有连接。

我正在构建一个单页应用程序,其标题包含三个通用反应组件和一个主要内容容器。发生的事情是路线根本就没打过。我在那里放了一个notfoundroute只是为了确认和捕获未命中。我总是在NotFoundRoute上结束。任何人都可以指出任何明显我错过的东西吗?我的f /:formName路由有querystring params,但我的仪表板没有,我不认为这些因素,但是...... FYI。

...

//===================== SPA components ============================//

var ObjectForm = require('./components/form.react');
var Dashboard = require('./components/dashboard.react');
var NotFound = require('./components/notFound.react');

...

//===================== SPA container and router ============================//

var App = React.createClass({
    getInitialState: function(){
        console.log("getInitialState");
        storeManager.appInit();
        return null;
    },
    render: function(){
        return (<RouteHandler/>);
    }
});


//===================== Universal components (always accessible on any page in the application) ============================//

//menu
React.render(
    <MainMenu />,
    document.getElementById('mainMenuContainer')
);

//bucket
React.render(
    <BucketList />,
    document.getElementById('bucketList')
);

//search
React.render(
    <InstantBox />,
    document.getElementById('globalSearchForm')
);


//===================== application routes (apply to SPA mounted into appContent div) ============================//

var routes = (
  <Route name="App" path="/" handler={App}>
    <Route name="Dashboard" path="dashboard" handler={Dashboard}/>
    <Route name="ObjectForm" path="f/:formName" handler={ObjectForm}/>
    <NotFoundRoute handler={NotFound}/>
  </Route>
);


Router.run(routes, function (Handler) {
  React.render(<Handler/>, document.getElementById('appContent'));
});

1 个答案:

答案 0 :(得分:0)

对于任何想知道的人,在Router.run中需要看起来像Router.HistoryLocation。不是根据github上的文档,虽然....任何人都可以澄清文档是不是现在还是为什么Router.HistoryLocation的遗漏会破坏路由器?我很想知道发生了什么。

总之,使用:

Router.run(routes, Router.HistoryLocation, function (Handler) {
  React.render(<Handler/>, document.getElementById('appContent'));
});

而不是:

Router.run(routes, function (Handler) {
  React.render(<Handler/>, document.getElementById('appContent'));
});

另请参阅:React Router 0.11.1 routes all requests to Home