问题描述
我正在将 react js 转移到下一个 js,我在 react 路由器中遇到了一些问题,假设我有很多仪表板路由,而这些路由必须通过 login
,所以我必须通过所有仪表板通过登录路由,如果用户未登录则重定向到登录路由。
我的反应RouteWithAuthLayout
const RouteWithAuthLayout = props => {
const { layout: Layout,component: Component,...rest } = props;
return (
<Route
{...rest}
render={matchProps => {
if (!loggedIn()) {
return (
<Redirect
to={{
pathname: "/auth/login",search: "?next="+window.location.pathname
}}
/>
)
}
return (
<Layout>
<Component {...matchProps} />
</Layout>
)
}}
/>
);
};
我的Dashboard.js
看起来像这样
<Switch>
<RouteWithAuthLayout
component={BuyShipProductDetail}
layout={DashboardLayout}
exact
path="/dashboard/buy-ship-for-me/product/:productNumber/detail"
/>
</Switch>
和我的Router.js
<Route path="/dashboard">
<Dashboard />
</Route>
是否有任何类函数可以将我的 react 路由器转换为下一个路由器?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)