first install router via: npm install router
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
import { Routes, RouterModule } from '@angular/router';
export const router: Routes = [
{ path: '', redirectTo: 'main', pathMatch: 'full'},
{ path: 'main', component:AdminBodyComponent },
{ path: 'admin', component:AdminComponent },
{ path: 'posts',component:PostsComponent},
{ path: 'addposts',component:AddPostComponent}];
export const routes: ModuleWithProviders = RouterModule.forRoot(router);
step2:
inject into your .ts file
constructor(
private router:Router,
...
)
step3:
this.router.navigate(['/addposts']);
step4:
<base href="/">
<!-- end snippet -->
if you want to use specific router go for this
step4:<base href="/">
first install router via: npm install router
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
import { Routes, RouterModule } from '@angular/router';
export const router: Routes = [
{ path: '', redirectTo: 'main', pathMatch: 'full'},
{ path: 'main', component:AdminBodyComponent },
{ path: 'admin', component:AdminComponent },
{ path: 'posts',component:PostsComponent},
{ path: 'addposts',component:AddPostComponent}];
export const routes: ModuleWithProviders = RouterModule.forRoot(router);
step2:
inject into your .ts file
constructor(
private router:Router,
...
)
step3:
this.router.navigate(['/addposts']);
<!-- end snippet -->
if you want to use specific router go for this
step4:<base href="/">