I'm trying to navigate to a different page in Angular 6.
In Ionic we do it by calling navCtrl.push('ExamplePage');
In Angular 6 I understand they are routes but I'm not being able to navigate using a button like:
app.component.html
<button (click)='goToExamplePage()'>ExamplePage</button>
<router-outlet></router-outlet>
app.component.ts
import {Router} from '@angular/router';
constructor(private router: Router)
goToExamplePage(){
this.router.navigate(['/example'])
}
app.module.ts
import { RouterModule, Routes } from '@angular/router';
const appRoutes: Routes = [
{path: '', component: AppComponent},
{ path: 'example', component: ExampleComponent }
];
@NgModule({
declarations: [
AppComponent,
ExampleComponent
],
imports: [
RouterModule.forRoot(
appRoutes,
{ enableTracing: true } // <-- debugging purposes only
)
...
],
bootstrap: [AppComponent],
exports: [
RouterModule
]
})
It simply doesn't do anything. Any help please?