react router + redux 警告:位置 "xyz" 不匹配任何路由
react router + redux Warning: Location "xyz" did not match any routes
我正在尝试在我的 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
如有任何解决方法的提示,我将不胜感激
您需要使用绝对路径而不是名称。
<Link to='/quiz'>Quiz</Link>
请参阅 Link 组件文档 here
我正在尝试在我的 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
如有任何解决方法的提示,我将不胜感激
您需要使用绝对路径而不是名称。
<Link to='/quiz'>Quiz</Link>
请参阅 Link 组件文档 here