zoukankan      html  css  js  c++  java
  • react项目如何设置404页面

    首先创建一个报错页面, 然后在路由页面中引入

    const ErrorPage = loadable(() => import('../pages/Error'));
    const BasicRoute = () => {
        return (
            <BrowserRouter>
                <Switch>
                    <Route exact path="/" render={() => (
                        Boolean(sessionStorage.getItem("token")) ? (
                            <Redirect to="/online" />
                        ) : (
                                <Home />
                            )
                    )} />
                    <Route exact path="/login" render={() => (
                        Boolean(sessionStorage.getItem("token")) ? (
                            <Redirect to="/online" />
                        ) : (
                                <Login />
                            )
                    )} />
                    <Route exact path="/regist" render={() => (
                        Boolean(sessionStorage.getItem("token")) ? (
                            <Redirect to="/online" />
                        ) : (
                                <Regist />
                            )
                    )} />
                    <Route exact path="/dating" render={() => (
                        Boolean(sessionStorage.getItem("token")) ? (
                            <Redirect to="/online" />
                        ) : (
                                <Dating />
                            )
                    )} />
                    <Route exact path="/inbox" render={() => (
                        Boolean(sessionStorage.getItem("token")) ? (
                            <Redirect to="/online" />
                        ) : (
                                <Inbox />
                            )
                    )} />
                    <Route exact path="/meetyou" render={() => (
                        Boolean(sessionStorage.getItem("token")) ? (
                            <Redirect to="/online" />
                        ) : (
                                <Meetyou />
                            )
                    )} />
                    <Route exact path="/insearch" render={() => (
                        Boolean(sessionStorage.getItem("token")) ? (
                            <Redirect to="/online" />
                        ) : (
                                <InSearch />
                            )
                    )} />
                    <Route exact path="/mycity" render={() => (
                        Boolean(sessionStorage.getItem("token")) ? (
                            <Redirect to="/online" />
                        ) : (
                                <Mycity />
                            )
                    )} />
                    <Route exact path="/lastsignup" render={() => (
                        Boolean(sessionStorage.getItem("token")) ? (
                            <Redirect to="/online" />
                        ) : (
                                <Lastsignup />
                            )
                    )} />
                    <Route exact path="/witheme" render={() => (
                        Boolean(sessionStorage.getItem("token")) ? (
                            <Redirect to="/online" />
                        ) : (
                                <Witheme />
                            )
                    )} />
                    <PrivateRoute exact path="/online" component={Online} />
                    <PrivateRoute exact path="/myresume:key" component={Myresume} />
                    <PrivateRoute exact path="/search" component={onSearch} />
                    <PrivateRoute exact path="/like" component={meLike} />
                    <PrivateRoute exact path="/city" component={onCity} />
                    <PrivateRoute exact path="/personinfo" component={perosenInfo} />
                    <PrivateRoute exact path="/conver" component={converSation} />
                    <PrivateRoute exact path="/chat" component={chitChat} />
                      放在最后面 只要路径不匹配就出现此页面
                    <Route component={ErrorPage}></Route>
                </Switch>
            </BrowserRouter>
        )
    }
    export default BasicRoute

      

  • 相关阅读:
    P1604&P1601
    【USACO OPEN 10】hop
    [usaco2008feb_gold]路面修整
    bzoj1016: [JSOI2008]最小生成树计数
    bzoj1015: [JSOI2008]星球大战starwar
    bzoj1014: [JSOI2008]火星人prefix
    [bzoj3223]文艺平衡树
    bzoj3224: Tyvj 1728 普通平衡树
    bzoj1012: [JSOI2008]最大数maxnumber
    P3369 【模板】普通平衡树 (splay 模板)
  • 原文地址:https://www.cnblogs.com/taxun/p/13433891.html
Copyright © 2011-2022 走看看