简体   繁体   中英

react router + redux Warning: Location “xyz” did not match any routes

I'm trying to make a routing in my react and redux application, but still not luck.

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'));

Default view is generated properly. In DashboardApp I have code like:

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

If I click on it I get error in console:

Warning: Location "quiz" did not match any routes

I would appreciate any hint how to solve it

You'll need to use absolute path instead of the name.

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

See Link component documentation as described here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM