react-router-如何正确简单快速的设置404页面

28次阅读

共计 616 个字符,预计需要花费 2 分钟才能阅读完成。

http://react-guide.github.io/…
官方文档半天打不开真是最致命的
搜了一堆试了都不行 什么加 switch 加一堆都没用
官方文档终于打开了 – –

    <Route path="/" component={App}>
      <Route path="about" component={About}/>
      <Route path="users" component={Users}>
        <Route path="/user/:userId" component={User}/>
      </Route>
      <Route path="*" component={NoMatch}/>
    </Route>

只需一行代码

<Route path="*" component={NoMatch}/>

component 里填自己想要显示的默认组件就可以了

注意
要加在自己 Route 的最下面
要加在自己 Route 的最下面
要加在自己 Route 的最下面

<Route path="about" component={About}/>
<Route path="about" component={About}/>
<Route path="about" component={About}/>
<Route path="about" component={About}/>
<Route path="about" component={About}/>
    //...
<Route path="*" component={NoMatch}/>

正文完
 0