简体   繁体   中英

Angular Force Reload

i am trying to do a forced reload after a logout.

I am using NGRX and after a logout dispatch action, i am trying to:

        this.router.navigated = false;
        this.router.navigate(['/login']);

Because i need to reload a imported file at my Theme Component.

  ngAfterViewInit() {
    import('../../assets/js/scripts.bundle.js');
  }

If I logout and try to login again, i am losing this JS, so a full reload can help me.

Any suggestions?

I cant put this .js on angular.json because i cant use him at a few pages.

After a logout, try doing window.location.reload(); .

And to be future proof where you want to do server side rendering, you should create the window like in the following post: How to Inject Window into Angular 2.1.0 .

But if you know you won't be doing server side rendering, just using window directly in your component should be fine.

I resolved with a href at logout button. Isnt the best solution i guess, but works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM