Reputation: 195
I am new in angular2 and I am trying to route through my component but I am getting error:
I know that the path is getting wrong but I don't know how to mention it in my config. below is my app.routing.ts
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
import { IndexComponent } from './home/index.component';
import { CarouselComponent } from './shared/carousel/carousel.component';
import { HeaderComponent } from './shared/header/header.component';
import { FooterComponent } from './shared/footer/footer.component';
import { MerchMngDashboardComponent } from './merchmng/dashboard/dashboard.component';
export const welcomeroutes: Routes = [
{ path: '', component: CarouselComponent, pathMatch: 'full' },
{ path: '', component: HeaderComponent, outlet: 'header' },
{ path: 'login', component: LoginComponent },
{ path: 'index', component: IndexComponent }
];
export const appRoutes: Routes = [
{ path: '', component: CarouselComponent, pathMatch: 'full' },
{ path: 'dashboard', component: MerchMngDashboardComponent },
]
;
this is my folder structure:
this is how I am using it in my index.component.html
<div class="dvIndexInnerHeader">
<a class="" [routerLink]="['dashboard']">MM</a>
</div>
and my index.module.ts:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { Routes } from '@angular/router';
import { APP_BASE_HREF } from '@angular/common';
import { HttpModule } from '@angular/http';
import { appRoutes } from '../app.routing';
import { IndexComponent } from './index.component'
@NgModule({
imports: [BrowserModule, FormsModule, HttpModule, appRoutes],
declarations: [IndexComponent],
exports: [IndexComponent]
})
export class IndexModule { }
Please help
Upvotes: 0
Views: 256
Reputation: 176
In your index.module.ts you can not pass your routes directly like that inside the imports. You need pass it like this:
@NgModule({
imports: [BrowserModule, FormsModule, HttpModule, RouterModule.forRoot(appRoutes)],
declarations: [IndexComponent],
exports: [IndexComponent]
})
I think this was only wrong with your code. I hope my answer was helpful. :)
Upvotes: 1