Javascript 角路由问题

Javascript 角路由问题,javascript,angular,typescript,angular-router,Javascript,Angular,Typescript,Angular Router,我已经定义了我的angular route,以便在用户未登录时重定向到登录页面,但每次我强制关闭浏览器并通过localhost重新访问我的angular应用程序时:4200/我没有重定向,我的应用程序显示空组件且没有重定向。我将其设计为在用户未使用AuthGuard登录时重定向到login,但即使用户登录,并且我可以在本地存储中看到应用程序数据,页面也或多或少保持空白。我知道有点不对劲,但我就是想不出来。这是我的app-routing.module.ts: 从'@angular/common/h

我已经定义了我的angular route,以便在用户未登录时重定向到登录页面,但每次我强制关闭浏览器并通过localhost重新访问我的angular应用程序时:4200/我没有重定向,我的应用程序显示空组件且没有重定向。我将其设计为在用户未使用AuthGuard登录时重定向到login,但即使用户登录,并且我可以在本地存储中看到应用程序数据,页面也或多或少保持空白。我知道有点不对劲,但我就是想不出来。这是我的app-routing.module.ts:

从'@angular/common/http'导入{HttpClientModule};
从“@angular/core”导入{NgModule};
从'@angular/router'导入{Routes,RouterModule};
从“./views/auth/signup/signup.component”导入{SignupComponent};
从“./views/auth/login/login.component”导入{LoginComponent};
从“./views/auth/reset/reset.component”导入{ResetComponent};
从'@angular/forms'导入{ReactiveFormsModule,FormsModule};
从“./views/error page/error page.component”导入{ErrorPageComponent};
从“ngx-toastr”导入{ToastrModule};
从“@angular/material/checkbox”导入{MatCheckboxModule};
从“@angular/material/button”导入{MatButtonModule};
从“@angular/common”导入{CommonModule};
常数路由:路由=[
{
路径:“”,
重定向到:'/login',
路径匹配:“已满”
},
{
路径:“登录”,
组件:LoginComponent
},
{
路径:'注册',
组件:注册组件
},
{
路径:“passwordreset”,
组件:重置组件
},
{
路径:'**',
组件:ErrorPageComponent,
数据:{title:'未找到页面'}
}
];
@NGD模块({
进口:[
公共模块,
FormsModule,
HttpClientModule,
匹配ECKBOxModule,
MatButtonModule,
反应形式模块,
forRoot(路由,{enableTracing:false,useHash:true}),
],
导出:[路由模块]
})
导出类AppRoutingModule{}
这是我的登录组件:


从“@angular/core”导入{Component,OnInit};
从'@angular/forms'导入{FormGroup,FormControl,Validators};
从'src/app/shared/util/validators/login.validators'导入{LoginValidator};
从“@angular/platform browser”导入{Title};
从'src/app/shared/services/login.service'导入{LoginService};
从'@angular/Router'导入{Router,ActivatedRoute};
从“ngx-toastr”导入{ToastrService};
@组成部分({
选择器:“登录”,
templateUrl:'./login.component.html',
样式URL:['./login.component.scss'],
})
导出类LoginComponent实现OnInit{
/**
*页面标题
*
*@var字符串
*/
标题='';
/**
*变量来检查是否需要动画类
*
*@var布尔值
*/
IsShakeClassRequired:Boolean=false;
/**
*用于检查用户是否选中“记住我”复选框的变量
*
*@var布尔值
*/
isRememberChecked:Boolean=true;
/**
*检查表格是否已提交
*
*@var布尔值
*/
isFormSubmitted:布尔值;
/**
*如果表单无效或包含无效输入
*
*@param Boolean
*/
isFormInValid:Boolean=false;
/**
*如果提供的登录详细信息正确。这应该是真的
*否则将显示错误消息
*
*@param Boolean
*/
isLoginInValid:Boolean=false;
/**
*服务器是否返回“错误请求”错误代码
*
*@var布尔值
*/
isBadRequestResponse:Boolean=false;
/**
*服务器是否返回“404未找到”错误代码
*
*@var布尔值
*/
isError404:Boolean=false;
/**
*加载动画
*@var布尔值
*/
加载:布尔值=false;
/**
*使用反应式表单方法的登录表单
*/
loginForm=新表单组({
LoginMail:new FormControl(“”,[Validators.required,Validators.email,LoginValidator.cannotContaineSpaces]),
loginpassword:new FormControl(“”,[Validators.required,Validators.minLength(6)])
});
/**
*用户所在的上一页
*@var字符串
*/
returnUrl:string;
/**
*如果已单击登录按钮,则将其设置为true
*@var布尔值
*/
isLoginProgressing:Boolean=false;
/**
*类构造函数
*
*@param-None
*/
建造师(
专用路由器:路由器,
私人页面标题:标题,
私人登录服务:登录服务,
专用路由:激活的路由,
私人toastrService:toastrService
)
{
this.pageTitle.setTitle(this.title);
}
ngOnInit():void{
如果(!localStorage.getItem('LoggedInUser')){
this.loginService.logout();
this.returnUrl=this.route.snapshot.queryParams['returnUrl']| |'/login';
}否则
this.router.navigate([this.returnUrl?this.returnUrl:'dashboard']);
}
/**
*处理表单提交和登录
*
*@param-None
*/
提交的表格(){
this.isFormSubmitted=true;
this.isLoginProgressing=true;
如果(!this.loginForm.valid){
this.isFormInValid=true;
this.isshakelasseeded=true;
this.isLoginProgressing=false;
}否则{
this.loginService.login(this.email.value、this.password.value)
.订阅(响应=>{
如果(答复){
this.isLoginProgressing=false;
让returnUrl=this.route.snapshot.queryParamMap.get('returnUrl')
this.router.navigate([returnUrl | |'/dashboard']))
}否则{
this.isLoginInValid=true;
this.isshakelasseeded=true;
this.isLoginProgressing=false;
}
},
错误=>{
如果(error.status==400){
this.isshakelasseeded=true;
this.isBadRequestResponse=true;
this.isLoginProgressing=false;
this.toastrService.error('出现问题。请检查您的连接','登录错误'{
超时:34000