路由 - react-router v5 - 总是点击 NotFound

问题描述

我正在尝试为我的应用程序添加一个登陆页面,在授权之后。登陆页面后的路线总是点击 NotFound 路线。我无法找出原因。

最初的路线是:

const Initial = ({settings}) => {
    const store = setupStore(reducers,{settings});
    return (
        <Provider store={store}>
            <AuthProvider appSettings={settings}>
                <Router basename={settings.Appcontextpath}>
                    <MainLayout>
                        <Switch>
                            Route
                                path={LOGIN_URL}
                                component={Login}
                            />
                            <Route
                                path={logoUT_URL}
                                component={logout}
                            />
                            <Route
                                exact={true}
                                path={SILENT_RENEW_URL}
                                component={SilentRenew}
                            />
                            <AuthenticatedRoute>
                                <App>
                                    <Switch>
                                        <Route
                                            exact path="/"
                                            component={LandingPage}
                                        />
                                        <Route component={NotFound} />
                                    </Switch>
                                </App>
                            </AuthenticatedRoute>
                        </Switch>
                    </MainLayout>
                </Router>
            </AuthProvider>
        </Provider>
    );
};

在登陆页面组件中,我添加了其余的路由,这些路由应该基于点击登陆页面链接

const FeatureRoutes = () => {
   
    return (
        <Switch>
            <Route
                path={`/:Id/feature1`}
                component={Feature1}
            />
            <Route
                path={`/:Id/feature2`}
                component={Feature2}
            />            
            <Route exact path={`/:Id`} component={Features} />
        </Switch>
    );
};

export default FeatureRoutes;

点击链接正确导航到带有 /:id 的 url,但它显示 NotFound 页面

请告诉我我做错了哪一部分?

TIA

解决方法

我可以通过更改路线来解决它直到“功能”路线:

<AuthProvider appSettings={settings}>
                <Router basename={settings.AppContextPath}>
                    <MainLayout>
                        <Switch>
                            Route
                                path={LOGIN_URL}
                                component={Login}
                            />
                            <Route
                                path={LOGOUT_URL}
                                component={Logout}
                            />
                            <Route
                                exact={true}
                                path={SILENT_RENEW_URL}
                                component={SilentRenew}
                            />
                            <AuthenticatedRoute>
                                <App>
                                    <Switch>
                                        <Route
                                            exact path="/"
                                            component={LandingPage}
                                        />
                                        <Route
                                            path={'/:Id'}
                                            component={FeatureRoutes}
                                        />
                                    </Switch>
                                </App>
                            </AuthenticatedRoute>
                        </Switch>
                    </MainLayout>
                </Router>
            </AuthProvider>
        </Provider>
    );
};

我将 NotFound 路由移到了 FeatureRoutes。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...