【发布时间】:2016-02-07 09:26:24
【问题描述】:
我有这样的路由器设置:
import React from 'react';
import {IndexRoute, NotFoundRoute, Route, Redirect} from 'react-router';
import App from './components/app';
import Home from './components/Home';
import AuthorPage from './components/authors/AuthorPage';
import About from './components/about/About';
import NotFound from './components/NotFound';
const routes = (
<Route path="/" component={App} >
<IndexRoute component={Home} />
<Route path="about" component={About} />
<Route path="authors" component={AuthorPage} />
<Route path="*" component={NotFound} />
<Redirect from="/about-us" to="/about" />
</Route>
);
export default routes;
除了重定向之外的一切都很好。每当我尝试导航到/about-us 时,我都会看到一个显示Cannot GET /about-us 的白页。
在文档中似乎找不到任何关于此的内容。路线的“来自”部分是否仍然必须存在才能使其正常工作,还是无论如何都应该重定向我?
编辑:
我还要提一下,我使用了 history 包,正如 react-router 升级指南中提到的那样:https://github.com/rackt/react-router/blob/master/upgrade-guides/v1.0.0.md
这是我的 main.js:
import React from 'react';
import ReactDOM from 'react-dom';
import Router from 'react-router';
import routes from './routes';
import createBrowserHistory from 'history/lib/createBrowserHistory'
// Using history to avoid default behavior of weird urls like `?_k=umhx1s`
// See: https://github.com/rackt/react-router/blob/master/upgrade-guides/v1.0.0.md
let history = createBrowserHistory();
const root = document.getElementById('app');
ReactDOM.render(<Router history={history}>{routes}</Router>, root);
【问题讨论】:
标签: reactjs react-router webpack-dev-server