26

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

Omar Abdelhady
  • 1,218
  • 3
  • 16
  • 27

3 Answers3

96

Simple

this.router.navigate(['path/to'])
  .then(() => {
    window.location.reload();
  });
Vlad
  • 6,741
  • 2
  • 48
  • 42
7

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();
  }
});
danielreiser
  • 5,182
  • 5
  • 29
  • 43
4

Simply do

location.href = '/admin/dashboard';
Priesten
  • 41
  • 3