我正在尝试在`react-router-dom v6.0中组织路由。这是我的流程:
根应用程序组件
function AppComponent() {
return <AppRoute />;
}
Run Code Online (Sandbox Code Playgroud)
AppRoute.js(基本路由)
const AppRoute = () => {
return (
<>
<GuestRoute path="/login" component={Login} />
</>
);
};
Run Code Online (Sandbox Code Playgroud)
访客路线
const GuestRoute = ({ component: Component, ...rest }) => {
return (
<GuestLayout>
<Routes>
<Route {...rest} element={<Component />} />
</Routes>
</GuestLayout>
);
};
Run Code Online (Sandbox Code Playgroud)
宾客布局
const GuestLayout = ({ children, ...rest }) => {
return (
<div>
{children}
</div>
);
};
Run Code Online (Sandbox Code Playgroud)
但是,当我转到 时/login,它并没有破坏页面,但仍然显示 的警告No routes matched location "/login"。我在用react-router-dom …