我正在测试此示例关于角度stackblitz中的登录注册问题是,当您登录并刷新浏览器页面时,authguard会重定向到登录页面。我必须修复此问题并重定向到当前页面。希望有人可以帮忙解决这个问题。谢谢。
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const currentUser = this.authenticationService.currentUserValue;
if (currentUser) {
// authorised so return true
return true;
}
else {
// not logged in so redirect to login page with the return url
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }
});
return false;
}
}
它现在正在工作,我只是让路由器导航代码进入else
部分。检查stackblitz