react-router4 中设置NoMatch不起作用,如何解决?

根据官网文档我这样设置NoMatch,但是当页面找不到没有跳转到NoMatch页面这是为什么?

<Router>
            <Switch>
                <Route exact path="/account/register" component={Register}/>
                <Route exact path="/account/login" component={Login}/>
                <Route exact path="/email/verify/:token" component={VerifyEmail}/>
                <Route path="/" component={Layout}/>
                <Route component={NoMatch}/>
            </Switch>
    </Router>

这是NoMatch组件:

import React from 'react'
import { withStyles } from 'material-ui/styles'

const styles = theme=>({

});

class NoMatch extends React.Component{
    constructor(props){
        super(props);
    }
    render(){
        return(
            <div>404 not found </div>
        )
    }
}

export default withStyles(styles)(NoMatch)
阅读 3k
1 个回答
<Route path="/" component={Layout}/>

加上exact

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题