acdlite / redux-router

Redux bindings for React Router – keep your router state inside your Redux store
MIT License
2.3k stars 200 forks source link

Failed prop type: The prop history is marked as required in Router, but its value is undefined #290

Open wohuifude123 opened 7 years ago

wohuifude123 commented 7 years ago

Version

"react-dom": "^15.6.1", "react-router": "^4.2.0", "react-router-dom": "^4.2.2"

Steps to reproduce

import React from 'react'
import {
    BrowserRouter as Router,
    Route,
    Link
} from 'react-router-dom'

const BasicExample = () => (
    <Router>
        <div>
            <ul>
                <li><Link to="/">Home</Link></li>
                <li><Link to="/about">About</Link></li>
                <li><Link to="/topics">Topics</Link></li>
            </ul>

            <hr/>

            <Route exact path="/" component={Home}/>
            <Route path="/about" component={About}/>
            <Route path="/topics" component={Topics}/>
        </div>
    </Router>
)

const Home = () => (
    <div>
        <h2>Home</h2>
    </div>
)

const About = () => (
    <div>
        <h2>About</h2>
    </div>
)

const Topics = ({ match }) => (
    <div>
        <h2>Topics</h2>
        <ul>
            <li>
                <Link to={`${match.url}/rendering`}>
                    Rendering with React
                </Link>
            </li>
            <li>
                <Link to={`${match.url}/components`}>
                    Components
                </Link>
            </li>
            <li>
                <Link to={`${match.url}/props-v-state`}>
                    Props v. State
                </Link>
            </li>
        </ul>

        <Route path={`${match.url}/:topicId`} component={Topic}/>
        <Route exact path={match.url} render={() => (
            <h3>Please select a topic.</h3>
        )}/>
    </div>
)

const Topic = ({ match }) => (
    <div>
        <h3>{match.params.topicId}</h3>
    </div>
)

export default BasicExample

Expected Behavior

It should work

Actual Behavior

It doesn't work

warning.js:35 Warning: Failed prop type: The prop history is marked as required in Router, but its value is undefined. in Router (created by RouterApp) in RouterApp printWarning @ warning.js:35 warning @ warning.js:59 checkReactTypeSpec @ checkReactTypeSpec.js:80 validatePropTypes @ ReactElementValidator.js:162 createElement @ ReactElementValidator.js:216 render @ router02.js:14 (anonymous) @ ReactCompositeComponent.js:795 measureLifeCyclePerf @ ReactCompositeComponent.js:75 _renderValidatedComponentWithoutOwnerOrContext @ ReactCompositeComponent.js:794 _renderValidatedComponent @ ReactCompositeComponent.js:821 performInitialMount @ ReactCompositeComponent.js:361 mountComponent @ ReactCompositeComponent.js:257 mountComponent @ ReactReconciler.js:45 performInitialMount @ ReactCompositeComponent.js:370 mountComponent @ ReactCompositeComponent.js:257 mountComponent @ ReactReconciler.js:45 mountComponentIntoNode @ ReactMount.js:104 perform @ Transaction.js:143 batchedMountComponentIntoNode @ ReactMount.js:126 perform @ Transaction.js:143 batchedUpdates @ ReactDefaultBatchingStrategy.js:62 batchedUpdates @ ReactUpdates.js:97 _renderNewRootComponent @ ReactMount.js:319 _renderSubtreeIntoContainer @ ReactMount.js:401 render @ ReactMount.js:422 (anonymous) @ main.js:73 webpack_require @ bootstrap 669b1c396b5c27223987:1334 fn @ bootstrap 669b1c396b5c27223987:741 (anonymous) @ main.bundle.js:23047 webpack_require @ bootstrap 669b1c396b5c27223987:1334 module.exports @ bootstrap 669b1c396b5c27223987:1383 (anonymous) @ bootstrap 669b1c396b5c27223987:1383 Router.js:31 Uncaught TypeError: Cannot read property 'location' of undefined at new Router (Router.js:31) at ReactCompositeComponent.js:294 at measureLifeCyclePerf (ReactCompositeComponent.js:75) at ReactCompositeComponentWrapper._constructComponentWithoutOwner (ReactCompositeComponent.js:293) at ReactCompositeComponentWrapper._constructComponent (ReactCompositeComponent.js:279) at ReactCompositeComponentWrapper.mountComponent (ReactCompositeComponent.js:187) at Object.mountComponent (ReactReconciler.js:45) at ReactCompositeComponentWrapper.performInitialMount (ReactCompositeComponent.js:370) at ReactCompositeComponentWrapper.mountComponent (ReactCompositeComponent.js:257) at Object.mountComponent (ReactReconciler.js:45)

MiguelMDSDP commented 4 years ago

Hey bro, I was getting the same error and I found that:

Version 4 of React Router changed things around a bit. They made separate top level router elements for the different history types. If you're using version 4 you should be able to replace with and the appropriate import.

I hope that it works to you too! :)