Try setting up your routes in the follow way, utilizing a redirectTo
to route the user to path "/trends" on startup.
Make sure you are importing RouterModule into your NgModule
. For the root module or similar you'd use RouterModule.forRoot(ROUTES)
and for feature modules you'd use RouterModule.forChild(ROUTES)
. Be sure to include <router-outlet></router-outlet>
in both the root and in any feature modules.
const ROUTES: Routes = [
{ path: 'trends', component: TrendsComponent },
{ path: '', redirectTo: '/trends', pathMatch: 'full' }
];
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello World</h2>
<p>Redirect to path /trends component is occurring on startup</p>
<router-outlet></router-outlet>
</div>
`,
})
export class App {}
@NgModule({
imports: [ BrowserModule, RouterModule.forRoot(ROUTES) ],
declarations: [ App, TrendsComponent ],
bootstrap: [ App ]
})
export class AppModule {}
Here is a plunker demonstrating the functionality.
Updated: plunker has been updated to show declaring and importing child routes and modules (non lazy loading).
Hopefully that helps.