HiveBrain v1.2.0
Get Started
← Back to all entries
snippettypescriptangularMajor

How to reload the current route with the angular 2 router

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
angularwithhowroutethecurrentrouterreload

Problem

I am using angular 2 with hashlocation strategy.

The component is loaded with that route:
"departments/:id/employees"


So far fine.

After I do a successful batch save of multiple edited table rows I want to reload the current route URL via:
this.router.navigate([departments/${this.id}/employees]);


But nothing happens, why?

Solution

If your navigate() doesn't change the URL that already shown on the address bar of your browser, the router has nothing to do. It's not the router's job to refresh the data. If you want to refresh the data, create a service injected into the component and invoke the load function on the service. If the new data will be retrieved, it'll update the view via bindings.

Context

Stack Overflow Q#40983055, score: 57

Revisions (0)

No revisions yet.