在react.js中使用嵌套路由时,如何创建404页面?

时间:2018-12-25 22:23:19

标签: reactjs react-router react-router-dom

我想为非我所选择的路线之一添加任何页面。我不知道将其放在代码中的哪个位置,因此404页不会与其他路径一起显示。

通常我应该将其放在的底部,但是由于嵌套的路线,我对放置位置感到困惑。

    render() {
    return (
        <Provider store={store}>
            <Router>
                <div className='App'>
                    <Navbar />
                    <Route exact path='/' component={Landing} />
                    <div className='container'>
                        <Route exact path='/register' component={Register} />
                        <Route exact path='/login' component={Login} />
                        <Route exact path='/profiles' component={Profiles} />
                        <Switch>
                            <PrivateRoute exact path='/dashboard' component={Dashboard} />
                        </Switch>
                        <Switch>
                            <PrivateRoute exact path='/create-profile' component={CreateProfile} />
                        </Switch>
                        <Switch>
                            <PrivateRoute exact path='/edit-profile' component={EditProfile} />
                        </Switch>
                        <Switch>
                            <PrivateRoute exact path='/vacations' component={Vacations} />
                        </Switch>
                        <Switch>
                            <PrivateRoute exact path='/add-vacation' component={VacationForm} />
                        </Switch>
                        <Switch>
                            <PrivateRoute exact path='/vacation/:id' component={Vacation} />
                        </Switch>
                        <Switch>
                            <PrivateRoute exact path='/chart' component={Chart} />
                        </Switch>
                    </div>
                    <Footer />
                </div>
            </Router>
        </Provider>
    );

它在确切路径中的其他组件之上或之下显示404Error组件

0 个答案:

没有答案