I want to make lazy loaded module in which i have 3 components. The main is Auth component(and signIn and signOut component). So i make the lazy loading and i load my module lazily, but i cant define router-outlet tag in my auth component to make child routes work.
import {NgModule} from '@angular/core'; import {Routes, RouterModule} from '@angular/router'; import {AuthorizationModule} from './authorization/authorization.module'; const routes: Routes = [ {path: 'auth', loadChildren: () => AuthorizationModule} ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule { }
import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {SignUpComponent} from './sign-up/sign-up.component'; import {SignInComponent} from './sign-in/sign-in.component'; import {AuthComponent} from './auth/auth.component'; const routes: Routes = [ { path: '', component: AuthComponent, children: [ {path: 'signIn', component: SignInComponent}, {path: 'signUp', component: SignUpComponent} ] } ]; @NgModule({ imports: [RouterModule.forChild(routes)], exports: [RouterModule] }) export class AuthRoutingModule { }
Import AuthRoutingModule
in your AuthorizationModule
@NgModule({
imports: [
AuthRoutingModule // Add this statement
]
})
export class AuthorizationModule{ }
You didn't provide which version of angular you're using, anyway in your AppRoutingModule
const routes: Routes = [ {
path: 'auth',
loadChildren: () => import('./path/to/your/auth/module/ts/file').then((m: AuthModule) => m.AuthModule)
}
];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.