0

I have a script that is loaded with JavaScript code in an angular application:

function reloadgame(gameId, user) {
  window.location  =  window.location.href.replace(/demo/ig, 'Real');
  return false;    
}

The script doesnt work, and my suspicion is because of the way angular works. The conventional known ways failed to work too such as the ways described here.

I tried to reload the page with this function:

location.reload();

and it worked.

However, I don't want to refresh the page. I want to redirect the user to a new path.

How can it be achieved given that I use JavaScript in an angular 5 app?

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
dan mann
  • 113
  • 1
  • 9

1 Answers1

0

I don't know which angular version you are expecting.

In Angular 2 and above

try this

import { Router, ActivatedRoute } from '@angular/router';

export class className{
 constructor(private router: Router) {
  }
  redirectToPage()
  {
   this.router.navigate(['yourpath']);// it will be redirect to your path 
  }
}

In angularjs

see this

How to redirect to another page using AngularJS?

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
  • That is interesting. But my javascript code isnt inside a typescript file, but in an external javascript file. – dan mann Apr 23 '18 at 15:20