react router + redux警告:位置“xyz”与任何路由都不匹配

时间:2015-10-14 14:00:09

标签: reactjs react-router redux

我正在尝试在react和redux应用程序中进行路由,但仍然没有运气。

index.js:

import React from 'react';
import { render } from 'react-dom';
import { Router, Route, IndexRoute } from 'react-router';
import { Provider } from 'react-redux';
import { createHistory } from 'history';

import DashboardApp from './containers/App';
import QuizApp from './containers/QuizApp';
import Page from './containers/Page';
import store from './store';

const routes = <Router history={createHistory()}>
    <Route path="/" component={Page}>
        <IndexRoute component={DashboardApp} />
        <Route path="quiz" component={QuizApp} />
    </Route>
</Router>;

render(
    <Provider store={store}>
        {routes}
    </Provider>, document.getElementById('app'));

正确生成默认视图。在DashboardApp我的代码如下:

<Link to='quiz'>Quiz</Link>

如果我点击它,我在控制台中收到错误:

Warning: Location "quiz" did not match any routes

我很感激任何提示如何解决它

1 个答案:

答案 0 :(得分:1)

您需要使用绝对路径而不是名称。

<Link to='/quiz'>Quiz</Link>

请参阅here

所述的链接组件文档
相关问题