簡體   English   中英

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>

請參閱此處所述的鏈接組件文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM