problem description
how to configure the route for the React project and keep reporting to: TypeError: Cannot read property "location" of undefined,?
the environmental background of the problems and what methods you have tried
found the document, all in the form of < Route path= "/ about" component= {About} / >, but I wrote it under
Baidu in a router folder. I only saw that one person was talking about the problem of the react-router version, saying that it would be fine to change the configuration in the package.json: "react-router": "^ 3.0.0" to 3.x. But I used the version of "react-router-dom": "^ 4.3.1"
and then Baidu looked for the react routing configuration file. I thought the writing of the gods was a little complicated, so I wanted to write a simple one first.
related codes
router/index.js
const routes = [{
path: "/invite",
component: () => import("../views/Invite/Invite")
}]
const router = (props) => (
<Router forceRefresh={!supportsHistory}>
<Switch>
<Route exact path="/" render={() => <Redirect to="/invite"/>} />
{routes.map(({ path, component }, index) => (
<Route
key={index}
exact
path={path}
component={component}
/>
))}
</Switch>
</Router>
)
export default router
what result do you expect? What is the error message actually seen?
error message:
not long after learning React, it is the first time to do React routing. Please help me to see what"s wrong. Thank you.