我正在使用角6制作一个应用程序,这里我有两个urls,
其中url 1是http://authentication.hello.com,url 2是http://application.hello.com
在这里,如果用户是loggen通过url 1将只能重定向到url 2。
但是,如果用户将url直接指定为http://application.hello.com,则应该将其重定向到http://authentication.hello.com进行登录。
我用了以下方法,
if (localStorage.getItem("isLoggedIn") === "true") {
return true;
} else {
window.location.href = "authentication.hello.com";
}在这里我用过
window.location.href = "authentication.hello.com";如果没有登录,则重定向到身份验证。
但是,如果用户直接以http://application.hello.com的形式给出url,那么它将显示as,http://application.hello.com/authentication.hello.com,这里它被添加到给定的url中,但我需要的是,它应该删除 http://application.hello.com,并且应该只有url作为http://authentication.hello.com,用户可以在其中看到登录屏幕。
对于window.location.replace("authentication.hello.com")来说,http://application.hello.com/authentication.hello.com的同样结果也即将到来,而我需要单独加载url authentication.hello.com,没有 application.hello.com的,如果不是loggedin的话。
请帮助我实现它使用纯javascript或类型记录。
发布于 2018-09-19 06:44:21
使用完整的URL在window.location.href中设置值:
window.location.href = "http://authentication.hello.com";https://stackoverflow.com/questions/52399597
复制相似问题