0

OS:Linuxのx64のUbuntuの16.04エラーガールート

アンギュラバージョンの角度-CLI

  • :1.0.0-beta.24
  • ノード:7.2.0
  • NPM :3.10.9

私はAngular CLIでプロジェクトを作成しましたが、私がページを更新すると、現在のルートが壊れています私のルートのパスでCanActivateを使用すると、私はそれを使用することができず、動作しますが、ルートを保護する必要があります。

これはあなたのapp.routing.tsファイルについてapp.routing.ts

const routes: Routes = [ 
    { path: '', component: LoginComponent }, 
    { path: 'reports', component: ReportsComponent, canActivate: [AuthGuard] }, 
    { path: 'reports/thirds', component: ReportThirdsComponent, canActivate: [AuthGuard] }, 
    { path: 'reports/profit-loss', component: ReportProfitLossComponent, canActivate: [AuthGuard] }, 
    { path: 'reports/balance', component: ReportBalanceComponent, canActivate: [AuthGuard] }, 
]; 
+0

guard&appモジュールコードを投稿できますか? –

答えて

1

で私のコードですが、私はすべてが正しいことだと思います。問題は、あなたのapp.module.tsファイルにすることができ

export class AuthGuard implements CanActivate { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) : Observable <boolean> | boolean{ return true|false; } }

:あなたのファイルAuthGuardと仮定すると、このようなものです。プロバイダのセクションであなたのガードを持つことは必須です。 このファイルに、このようなプロバイダセクションがあることを確認しましたか?

providers: [AuthGuard],