Any explain or doc about the difference between navigationEnd.url
and navigationEnd.urlAfterRedirects
?
Which one should I use if I want to write a breadcrumb
component?
My guess is that navigationEnd.url is your current url and navigationEnd.urlAfterRedirects is url that you will be redirected to if you navigate to navigationEnd.url.
NavigationEndlinkAn event triggered when a navigation ends successfully.
The Angular Routers triggers several events starting with when the Navigation starts ( NavigationStart ) and also when the Navigation end ( NavigationEnd ) successfully. It is triggered when the navigation is canceled either by the user ( NavigationCancel ) or due to an error in the navigation ( NavigationError).
It depends if you care about the URL that the user requested or the URL of the route that actually gets loaded.
If you define any routes with redirects, the two values will be different if the user navigates to a route that redirects to another route.
For example, take these routes (which components the routes load is not relevant, so they're excluded here):
{
path: "",
pathMatch: "full",
redirectTo: "home"
},
{
path: "home",
},
If the user navigates to /home
, then navigationEnd.url
and navigationEnd.urlAfterRedirects
will both be /home
.
If the user navigates to /
, then navigationEnd.url will be /
and navigationEnd.urlAfterRedirects will be /home
.
Even if you don't implement redirects, try to use the value that is most relevant to the the functionality you are basing on the url because you don't want to run into strange bugs later on if you add redirects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With