反应路由器工作不正确,只更改网址不查看



我不明白为什么不去页面,而只是更改URL。

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Link, withRouter } from 'react-router-dom'
import classify from 'src/classify'
import defaultClasses from './logo.scss'
import logo from './logo.svg'
class Logo extends Component {
static propTypes = {
classes: PropTypes.shape({
wrapper: PropTypes.string,
logo: PropTypes.string
})
}
render() {
const { classes, history } = this.props
return (
<Link to="/" className={classes.wrapper}>
<img className={classes.logo} src={logo} height="70"  alt="" title="" />
</Link>
)
}
}
export default classify(defaultClasses)(Logo)

withRouter() history.push也是如此 组件不呈现。

renderRoutes()我有下一条路 <Route exact path="/" component={Page} />

来自 App.js(main( 的 renderRoutes(( 调用

import React from 'react'
import { Switch, Route } from 'react-router-dom'
import Page from '../../Page'
import Journey from 'src/components/Journey'
const renderRoutingError = props => <ErrorView {...props} />
const renderRoutes = () => (
<Switch>
<Route exact path="/" component={Page} />
<Route exact path="/journey/" component={Journey} />
)
export default renderRoutes

使用上下文

this.props.pushContext({
nav: <Logo />,
background: 'white'
})

您忘了在renderRoutes中关闭Switch组件。

const renderRoutes = () => (
<Switch>
<Route exact path="/" component={Page} />
<Route exact path="/journey/" component={Journey} />
</Switch> <-- You forgot to close your Switch here.
)

最新更新