I am newbie in Angular, I want to implement the routes
in separate component and import the same component in app.module.ts
file. How do I import t
you should create a separate module for routing and add your router info in this module.
like this:
routing.module.ts
file structure
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './user/login/login.component'; //your component
const routes: Routes = [
{ path: 'login', component: LoginComponent}
];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [
RouterModule
]
})
export class RoutingModule { };
import RouterModule
and config your routs info then export your config (in export section of router module) for another module like app.module
.
then import and inject your routing module to your base module app.module
like this:
app.module.ts
file structure
import { RoutingModule } from './routing.module';
@NgModule({
declarations: [],
imports: [
RoutingModule
],
exports: [],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
AppRoutes is a class so you need to instanciate it before using it:
let appRoutes = new AppRoutes();
then
...
RouterModule.forRoot(appRoutes.getRoutes())