Trying to create a SPA with angular2:
Inside my main module I declare the routes and the components that I am about to use: mainApp.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, Routes } from '@angular/router';
import { BaseComponent,IndexComponent, ContactComponent,
PortfolioComponent, AboutComponent } from './BaseComponents';
const appRoutes: Routes = [
{ path: '', component: IndexComponent },
{ path: 'about', component: AboutComponent },
{ path: 'portfolio', component: PortfolioComponent},
{ path: 'contact', component: ContactComponent}
];
@NgModule({
imports: [ BrowserModule, RouterModule.forRoot(appRoutes)],
declarations: [ BaseComponent, IndexComponent, ContactComponent,
PortfolioComponent, AboutComponent ],
bootstrap: [ BaseComponent ]
})
export class AppModule { }
So, it's clear that I bootstrap the BaseComponent So inside the BaseComponent.ts I import the followings:
import { Component } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { IndexComponent, AboutComponent, PortfolioComponent,
ContactComponent} from '../BaseComponents';
and inside the template:
<a [routerLink]='index'>index</a>
<a [routerLink]='portfolio'>portfolio</a>
<a [routerLink]='about'>about</a>
<a [routerLink]='contact'>contact</a>
<router-outlet></router-outlet>
If I type manualy inside the url, then I do navigate to the upper paths. But if I click on them, no reaction.. Debugger doesn't give any error-warning.
Any help is welcome!
<a [routerLink]='[index]'>index</a>etc, gives me undefined imgur.com/a/EBmGc