在重新加载时,路由更改为基本URL无关紧要

时间:2018-11-24 12:11:00

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

这是我的路由器代码, 所以有两种类型的用户,并且路由是根据它们的。

首先,我检查它是否是经过身份验证的用户。

管理路由

  adminRoutes() {
      return (
          <Switch>
            <Route exact path="/dashboard" component={DashboardPage} />
            <Route exact path="/videos" component={AdminVideo} />
            <Redirect to="/dashboard" />
          </Switch>
        );
       }

登录路线

  loginRoutes() {
    return <Switch>
    <Route exact path="/" component={LandingPage} />
    <Redirect to="/" />
   </Switch>
  }

用户路线

 userRoutes() {
    return <Switch>
          <Route exact path="/dashboard" component={teacher} />
          <Redirect to="/dashboard" />
        </Switch>
  }


  checkForRoutes() {
      if (this.props.isAuthenticatedUser) {
         if (this.props.userType === 1) {
            return this.adminRoutes(); // admin
         } else if (this.props.userType === 2) {
           return this.userRoutes(); // user
         }
      } else {
          return this.loginRoutes();
        }
      }

组件渲染方法

    render() {
      return (
      <BrowserRouter>
            {this.checkForRoutes()}
      </BrowserRouter>
    );
    }

因此,当我以管理员身份登录并转到/ videos并重新加载页面时,它将url更改为/ dashboard

请向我提供我尝试过多种方法但对我不起作用的解决方案。

0 个答案:

没有答案