Read Route Params From Directly Entered Url In App
My question would be regarding angular 4, how to get route params, if for example a user gets on your page with, instead of the default url, like for example http://localhost:3000/
Solution 1:
Your way is already ok, but in your example params
is an array and you can access to :id
by calling params['id']
:
this.sub = this.route.params.subscribe(params => {
console.log('params are', params['id']);
});
Here is an working example on stackblitz.
Solution 2:
Access current url
via Location
public constructor(location:Location) {
let url = location.prepareExternalUrl(location.path());
}
and parse out id
from this.
Post a Comment for "Read Route Params From Directly Entered Url In App"