我已将路由器配置为重定向到' /'路线:
let PrivateRoute = ({ component: Component, ...rest }: any) => (
<Route {...rest} render={PrivateRender(Component)} />
);
let PrivateRender = (Component: any) => {
return (props: any) => {
return securityApi.isAuthenticated().then(x =>
x ? (<Component {...props} />)
: (<Redirect to={{ pathname: '/', state: { from: props.location } }} />)
)
}
};
export const routes = <Layout>
<Route exact path='/' component={Home} />
<PrivateRoute exact path='/lobby' component={Lobby} />
<PrivateRoute exact path='/lobby/blackjack' component={Blackjack} />
</Layout>;
它确实不正确,因为pf promise方法: securityApi.isAuthenticated()
以下是此方法:
isAuthenticated() {
return axios.get('/api/token/ping')
.then((response) => {
return true;
})
.catch(reason => {
return axios.post("/api/token/refresh", { refreshToken: window.sessionStorage.getItem("refresh_token") })
.then(() => {
return true;
// todo: update storages with new jws and refresh_token values
})
.catch((reason) => {
return false;
});
});
}
那么,如何解决这种情况?