react 路由 404页面配置

        <Switch>
          <Redirect from="/" to="/light/login" exact></Redirect>
          <Route path="/light/login" component={Login}></Route>
          <Route path="/light/index" component={Index}></Route>
          <Route path="/404" component={NotFound}></Route>
          <Redirect from="*" to="/404" exact></Redirect>
        </Switch>

二级路由需要同样的配置:

    listDom.push(<Redirect key="404" from="*" to="/404" exact></Redirect>)    

    <div className="m-list">
      <Header></Header>
      <div className="m-list-info">
        <Nav></Nav>
        <Suspense fallback={<Loading isLazyLoading={true}></Loading>}>
          <Switch>
            {listDom}
          </Switch>
        </Suspense>
      </div>
    </div>

posted @ 2021-07-24 09:56  徐同保  阅读(338)  评论(0编辑  收藏  举报