我不明白为什么不去页面,而只是更改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.
)