So I want to reload the app after navigating to a specific route ..
I use router.navigate to navigate to certain route based on user role and that works fine but I have to reload the page after routing if coming from sign in page (not every time user opens that certain route) - and reloading here is to update page language depending on user's language
so what i tried to do is
else if(this.sp.role === 'Admin') {
console.log('ooo')
this.router.navigate(['/admin/dashboard']);
this.window.location.reload();
but that reloads the sign in page
By default, the router will ignore this navigation. However, this prevents features such as a “refresh” button.
difference between the two navigateByUrl is similar to changing the location bar directly–we are providing the “whole” new URL. Whereas router. navigate creates a new URL by applying an array of passed-in commands, a patch, to the current URL.
Simple
this.router.navigate(['path/to'])
.then(() => {
window.location.reload();
});
What you could do is shift the reload logic to the actual component which needs to be reloaded. You can subscribe to the NavigationEnd event and then check the route you're coming from e.g.
this.router.events
.pipe(
filter(value => value instanceof NavigationEnd),
)
.subscribe(event => {
if (event.url === 'http://mypreviousUrl.com') {
this.window.location.reload();
}
});
Simply do
location.href = '/admin/dashboard';
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