How to use routerlink in angular2?
up vote
1
down vote
favorite
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
}
];
angular typescript
add a comment |
up vote
1
down vote
favorite
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
}
];
angular typescript
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
}
];
angular typescript
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
}
];
angular typescript
angular typescript
edited Nov 7 '16 at 10:14
Günter Zöchbauer
303k60889838
303k60889838
asked Nov 7 '16 at 10:04
Arnold
40110
40110
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
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]
gunter, edited with my routes.ts
– Arnold
Nov 7 '16 at 10:13
Have you tried my suggestions?
– Günter Zöchbauer
Nov 7 '16 at 10:14
This one worked [routerLink]="['/app/tables/basic']"
– Arnold
Nov 7 '16 at 10:29
add a comment |
up vote
0
down vote
if you want to route from button click you can easily use this, and also you can use it as a parameter parser through the components.firstly i will describe how to use it as a only for routing.
<a [routerLink]="['/user/complain']">complain</a>
from above example we can route the user/complain using complain tag
now i am going to describe the second one(how to parse the parameters through the components)
i will do it using the router params
<a [routerLink]="['/user/complain', job.id]">complain</a>
from that we can parse job.id to complain component.
in complain component.ts file -
export class ComplainComponent {
id: number;
private sub: any;
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
this.id = params['id']; // (+) converts string 'id' to a number
});
}
}
we can assign a variable for router parameter in this file.then you can easily whether is it worked or not by complain component.html file by
<h3>{{job.id}}</h3>
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
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]
gunter, edited with my routes.ts
– Arnold
Nov 7 '16 at 10:13
Have you tried my suggestions?
– Günter Zöchbauer
Nov 7 '16 at 10:14
This one worked [routerLink]="['/app/tables/basic']"
– Arnold
Nov 7 '16 at 10:29
add a comment |
up vote
1
down vote
accepted
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]
gunter, edited with my routes.ts
– Arnold
Nov 7 '16 at 10:13
Have you tried my suggestions?
– Günter Zöchbauer
Nov 7 '16 at 10:14
This one worked [routerLink]="['/app/tables/basic']"
– Arnold
Nov 7 '16 at 10:29
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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]
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]
answered Nov 7 '16 at 10:05
Günter Zöchbauer
303k60889838
303k60889838
gunter, edited with my routes.ts
– Arnold
Nov 7 '16 at 10:13
Have you tried my suggestions?
– Günter Zöchbauer
Nov 7 '16 at 10:14
This one worked [routerLink]="['/app/tables/basic']"
– Arnold
Nov 7 '16 at 10:29
add a comment |
gunter, edited with my routes.ts
– Arnold
Nov 7 '16 at 10:13
Have you tried my suggestions?
– Günter Zöchbauer
Nov 7 '16 at 10:14
This one worked [routerLink]="['/app/tables/basic']"
– Arnold
Nov 7 '16 at 10:29
gunter, edited with my routes.ts
– Arnold
Nov 7 '16 at 10:13
gunter, edited with my routes.ts
– Arnold
Nov 7 '16 at 10:13
Have you tried my suggestions?
– Günter Zöchbauer
Nov 7 '16 at 10:14
Have you tried my suggestions?
– Günter Zöchbauer
Nov 7 '16 at 10:14
This one worked [routerLink]="['/app/tables/basic']"
– Arnold
Nov 7 '16 at 10:29
This one worked [routerLink]="['/app/tables/basic']"
– Arnold
Nov 7 '16 at 10:29
add a comment |
up vote
0
down vote
if you want to route from button click you can easily use this, and also you can use it as a parameter parser through the components.firstly i will describe how to use it as a only for routing.
<a [routerLink]="['/user/complain']">complain</a>
from above example we can route the user/complain using complain tag
now i am going to describe the second one(how to parse the parameters through the components)
i will do it using the router params
<a [routerLink]="['/user/complain', job.id]">complain</a>
from that we can parse job.id to complain component.
in complain component.ts file -
export class ComplainComponent {
id: number;
private sub: any;
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
this.id = params['id']; // (+) converts string 'id' to a number
});
}
}
we can assign a variable for router parameter in this file.then you can easily whether is it worked or not by complain component.html file by
<h3>{{job.id}}</h3>
add a comment |
up vote
0
down vote
if you want to route from button click you can easily use this, and also you can use it as a parameter parser through the components.firstly i will describe how to use it as a only for routing.
<a [routerLink]="['/user/complain']">complain</a>
from above example we can route the user/complain using complain tag
now i am going to describe the second one(how to parse the parameters through the components)
i will do it using the router params
<a [routerLink]="['/user/complain', job.id]">complain</a>
from that we can parse job.id to complain component.
in complain component.ts file -
export class ComplainComponent {
id: number;
private sub: any;
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
this.id = params['id']; // (+) converts string 'id' to a number
});
}
}
we can assign a variable for router parameter in this file.then you can easily whether is it worked or not by complain component.html file by
<h3>{{job.id}}</h3>
add a comment |
up vote
0
down vote
up vote
0
down vote
if you want to route from button click you can easily use this, and also you can use it as a parameter parser through the components.firstly i will describe how to use it as a only for routing.
<a [routerLink]="['/user/complain']">complain</a>
from above example we can route the user/complain using complain tag
now i am going to describe the second one(how to parse the parameters through the components)
i will do it using the router params
<a [routerLink]="['/user/complain', job.id]">complain</a>
from that we can parse job.id to complain component.
in complain component.ts file -
export class ComplainComponent {
id: number;
private sub: any;
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
this.id = params['id']; // (+) converts string 'id' to a number
});
}
}
we can assign a variable for router parameter in this file.then you can easily whether is it worked or not by complain component.html file by
<h3>{{job.id}}</h3>
if you want to route from button click you can easily use this, and also you can use it as a parameter parser through the components.firstly i will describe how to use it as a only for routing.
<a [routerLink]="['/user/complain']">complain</a>
from above example we can route the user/complain using complain tag
now i am going to describe the second one(how to parse the parameters through the components)
i will do it using the router params
<a [routerLink]="['/user/complain', job.id]">complain</a>
from that we can parse job.id to complain component.
in complain component.ts file -
export class ComplainComponent {
id: number;
private sub: any;
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
this.id = params['id']; // (+) converts string 'id' to a number
});
}
}
we can assign a variable for router parameter in this file.then you can easily whether is it worked or not by complain component.html file by
<h3>{{job.id}}</h3>
answered 4 hours ago
malith vitha
512
512
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40462452%2fhow-to-use-routerlink-in-angular2%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password