首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用React路由器V4重定向至ReactJS组件上的服务器路由

使用React路由器V4重定向至ReactJS组件上的服务器路由
EN

Stack Overflow用户
提问于 2018-03-22 08:33:03
回答 2查看 1.5K关注 0票数 2

我的React路由器V4路由是这样构造的:

代码语言:javascript
复制
const isAuthenticated = () => {
    let hasToken = localStorage.getItem("jwtToken");
    if (hasToken) return true;
    return false;
};

const AuthenticatedRoute = ({ component: Component, ...rest }) =>
    <Route
        {...rest}
        render={props =>
            isAuthenticated()
                ? <Component {...props} />
                : <I NEED TO REDIRECT FROM HERE TO SERVER PAGE />}
    />;

class App extends Component {
    render() {
        return (
            <BrowserRouter basename="/editor">
                <Switch>
                    <AuthenticatedRoute exact path="/" component={AppNav} />
                    <AuthenticatedRoute
                        exact
                        path="/:module"
                        component={AppNav}
                    />
                    <AuthenticatedRoute
                        exact
                        path="/:module/:screen"
                        component={AppNav}
                    />
                    <AuthenticatedRoute
                        exact
                        path="/:module/:screen/:action"
                        component={AppNav}
                    />
                    <AuthenticatedRoute
                        exact
                        path="/:module/:screen/:action/:id"
                        component={AppNav}
                    />

                    <Route component={PageNotFoundError} />
                </Switch>
            </BrowserRouter>
        );
    }
}

export default App;

正如你在代码中看到的,如果没有通过身份验证,我想要重定向到服务器页面。该页面是另一个用于管理用户注册的react应用程序,它位于服务器中,但位于另一个路由树中:/registration

我尝试过但没有成功的东西:

代码语言:javascript
复制
<Redirect to="//registration' />
windows.location = "/registration"
windows.location.href = "/registration"
<Redirect to="http//registration' />
windows.location = "http://registration"
windows.location.href = "http://registration"

所有重定向到当前应用程序中的页面。

这个问题的解决方案是什么?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49418692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档