Angular 4如何在注销后重定向页面?
发布时间:2020-12-17 07:20:08 所属栏目:安全 来源:网络整理
导读:我知道这已经得到了回答,但我对给出的答案并不满意. 我的问题很简单,用户想要注销. 如果它位于需要登录的页面上(使用auth.service.ts在auth.guard.ts中设置)并且用户注销我希望将其重定向到主页. 但是,如果他在一个安全的页面上,我不想重定向他. 我可以使用A
我知道这已经得到了回答,但我对给出的答案并不满意.
我的问题很简单,用户想要注销. 如果它位于需要登录的页面上(使用auth.service.ts在auth.guard.ts中设置)并且用户注销我希望将其重定向到主页. 但是,如果他在一个安全的页面上,我不想重定向他. 我可以使用AuthGuard,但我不想重新加载页面,所以没有: location.reload() 我的选择是什么? import { Router } from '@angular/router'; ..... constructor(private router:Router,authService: AuthService){} //toastMessagesService: ToastMessagesService){} if you have one .... onLogOut(){ authService.logOut(); if (this.router.url==="/admin"){ //this.toastMessagesService.show("Logged out"); // display a toast style message if you have one :) this.router.navigate(["/home"]); //for the case 'the user logout I want him to be redirected to home.' } else{ // Stay here or do something // for the case 'However if he is on a safe page I don't want to redirected him.' } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |