Arnold Arnold - 1 month ago 14
TypeScript Question

How to use routerlink in angular2?

I am trying to redirect from one page to another using routerlink and I had tried the following code,

I have the following route as my url

http://localhost:3000/#/app/dashboard


I want to redirect to this,when i click on this

[routerLink]=" ['tables/basic'] "

http://localhost:3000/#/app/tables/basic


but it is going to

http://localhost:3000/#/app/dashboard/tables/basic


Here dashboard should be removed and how can I do that? Can anyone pls provide some help?

my routes.ts,

import { Routes } from '@angular/router';
import { ErrorComponent } from './error/error.component';


export const ROUTES: Routes = [{
path: '', redirectTo: 'app', pathMatch: 'full'
}, {
path: 'app', loadChildren: () => System.import('./layout/layout.module')
}, {
path: 'login', loadChildren: () => System.import('./login/login.module')
}, {
path: 'error', component: ErrorComponent
}, {
path: '**', component: ErrorComponent
}
];

Answer

Perhaps

[routerLink]="['../tables/basic']"

or

[routerLink]="['/app/tables/basic']"

To be sure you would need to provide the information what routes your application has configured and what component contains the [routerLink]