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

发布于 2022-09-05 23:21:39 字数 915 浏览 6 评论 0

根据官网文档我这样设置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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2022-09-12 23:21:39
<Route path="/" component={Layout}/>

加上exact

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文