Previously I’ve posted about finding current URL with Angular 2.0 Routing which was suitable for rc-1.
On Angular 2.0 rc-3, the angular router (alpha 3.0.0) has been added to the repository with much easier
API for getting the current URL.
Let’s have a look at the following code (Typescript)
What I did here was subscribe to the router events. There are some router events which we can subscribe to. Two of them are NavigationStart and NavigationEnd . The event instance can me constructed from either one of them, however, yet we cannot determine which one so although we’re interested in NavigatioEnd this code will run twice every route.
Nevertheless, we can (in much either way than the way presented in rc-1) get the current URL.