【发布时间】:2015-07-30 20:44:02
【问题描述】:
我正在尝试使用 react-router-component 将路由添加到我的简单博客/短篇小说应用程序,但无论输入什么 url,它都会显示相同的组件。会出现 url,但即使我指定了不同的处理程序,它总是呈现相同的组件,因此“localhost:3000/”和“localhost:3000/category”都显示相同的组件,即使我指定了不同的处理程序“ /类别”。该文件如下所示:
'use strict';
var React = require('react');
var Router = require('react-router-component');
var Locations = Router.Locations;
var Location = Router.Location;
var MainPage = require('./components/views/main-page.jsx');
var CategoryPage = require('./components/views/category-page.jsx');
var App = React.createClass({
render: function () {
return (
<Locations>
<Location path="/" handler={MainPage} />
<Location path="/category" handler={CategoryPage} />
</Locations>
)
}
})
React.render(<App />, document.body)
您可以在我的 github https://github.com/mrbgit/short-stories/tree/branch 上查看完整项目,如果您需要更多信息,请告诉我。谢谢!
【问题讨论】:
-
你没有运行你的路由器,这不是你在 React-Router 中创建路由的方式。 react-router 中的教程非常简单。
标签: javascript reactjs react-router-component