canActivateとcanLoadを2つの異なるモジュールレベルで使用しようとしましたが、まだ遅延ロードされたモジュールに直接アクセスできません。あなたが直接http://url.com/lazy
に移動していない場合は、上記のコードが動作するapp.routing.module.tscanLoadまたはcanActivateガードダイレクトURLを持つ角4遅延ロードモジュール/
import { AuthGuardImpl } from './lazy-load/auth-guard.service';
import {AuthGuard} from './lazy-load/auth.service';
const routes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'lazy', canLoad: [AuthGuardImpl], loadChildren: 'app/lazy-load/lazy-load.module#LazyLoadModule'},
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
imports: [
CommonModule,
RouterModule.forRoot(routes)
],
exports: [RouterModule],
declarations: [],
providers: [AuthGuardImpl, AuthGuardService]
})
で
。しかし、http://url.com/
に行き、lazyモジュールへのルータのリンクに従います。
は同様に私が試した:
再び、http://url.com/lazy
に直接行く動作しませんが、アプリのロード場合は動作し、ユーザーがrouterlinkによって
/lazy
にナビゲートします
import { AuthGuard } from './auth.service';
import { AuthGuardImpl } from './auth-guard.service';
const lazyRoutes: Routes = [
{ path: '', component: LazyLoadComponent, canActivate: [AuthGuardImpl],
children: [
{ path: 'dashboard', loadChildren: 'app/lazy-load/dashboard/dashboard.module#DashboardModule' },
{ path: '', redirectTo: 'dashboard', pathMatch: 'full'},
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(lazyRoutes)],
exports: [RouterModule],
declarations: [],
providers: [AuthGuardImpl, AuthGuard]
})
を。
ガードを使用する遅延ロードモジュールの直接URLに移動することはできますか?
私はこの問題を私のサービスで非同期の問題に絞り込んだ。私はそれを完全に解決したら、私の答えを更新します。 – Aluminum91