How to reload current route in angular 2
Most of the time we need to reload current URL with angular 2 but as there is no option so there are some tips to do that. So let’s start we will check one by one.
Reload current route with some dummy parameter
So now you can update refresh
query parameter value and subscribe it in following way.
So if your all work start from init
method then that would be easy to call again init
method. So here actually route is not reload you just got an event by this you trigger init
method again.
Pros: You call init method and things are done.
Cons: if your route using Reslover
then how will Resolver
data update? For this we are using next below trick :).
Reload current route with some dummy route
I prefer this way because by this all route will reload and thinks done automatically and in all project, you can use this thing and no worry about reload route. So basically, we need to create a blank component and set a route for this like below
So now like I want to refresh my route then I will subscribe this route and when it will come this subscribe callback I will navigate to current URL and it will run. So first it goes to blank route and then come to this route so all things reset according to current route :)
for any query, please comment or feedback me for this blog, how do you like this.