微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

有没有办法通过登录重定向将反应路由器转换为下一个路由器?

如何解决有没有办法通过登录重定向将反应路由器转换为下一个路由器?

我正在将 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 举报,一经查实,本站将立刻删除。