我的問題是,當我在瀏覽器更改URL它總是導致啓動路線,當我鍵入路徑相比存在於路由器別的其他的我得到404角路由器不適合瀏覽器的URL正確響應
APP-routing.module.ts
const routes: Routes = [
{path: "start", canActivate:[RoutingGuard], component: Start},
{path: "path-1", canActivate:[RoutingGuard], component: One},
{path: "path-2", canActivate:[RoutingGuard], component: Two},
{path: "path-3", canActivate:[RoutingGuard], component: Three},
{path: "path-4", canActivate:[RoutingGuard], component: Four},
{path: "", component: Public},
{path: "**", redirectTo: "", pathMatch:'full'}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
路由guard.service.ts:
canActivate() {
this._mysvc.isAuthorized().subscribe(data => this.auth = data);
if (!this.auth) {
this._router.navigate(['/']);
}
return this.auth;
}
我有一個登錄和公共分量i有這個方法重定向到/如果用戶已登錄開始
public.component.ts:
isAuthorized(authorized:boolean):void {
if (authorized) {
this._router.navigate(['/start']);
}
}
ngOnInit():void {
this._mysvc.isAuthorized().subscribe(this.isAuthorized.bind(this), this.isAuthorizedError);
}
的index.html:
<html lang="en">
<head>
<base href="/">
<!--<meta charset="UTF-8">-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<app-root></app-root>
</body>
</html>
我用改寫配置,所以我跳過#url中
rewrite.config:
RewriteRule /start/? /index.html [NC]
RewriteRule /path-1/? /index.html [NC]
RewriteRule /path-2/? /index.html [NC]
RewriteRule /path-3/? /index.html [NC]
RewriteRule /path-4/? /index.html [NC]
,你能否告訴我們的RoutingGuard的代碼?也許有一個重定向到/開始/?如果您在路由Guard中調用「isAuthorized」並且您已登錄,則當然會將您重定向到/開始/每次。扭轉局面,所以你檢查!授權 – MeMeMax
@MeMeMax我的問題增加了routingGuard代碼! – Hazu
是這樣的:「this._mysvc.isAuthorized()」與你的公共組件中的方法相同嗎? – MeMeMax