简体   繁体   English

角力重装

[英]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:我正在使用 NGRX 并且在注销调度操作后,我正在尝试:

        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.如果我注销并再次尝试登录,我将丢失此 JS,因此完全重新加载可以帮助我。

Any suggestions?有什么建议?

I cant put this .js on angular.json because i cant use him at a few pages.我不能把这个 .js 放在 angular.json 上,因为我不能在几页上使用他。

After a logout, try doing window.location.reload();注销后,尝试执行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 .并且为了将来证明您想要进行服务器端渲染,您应该像以下帖子中那样创建窗口: 如何将窗口注入 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.但是如果你知道你不会进行服务器端渲染,那么直接在你的组件中使用 window 应该没问题。

I resolved with a href at logout button.我在注销按钮上使用 href 解决了问题。 Isnt the best solution i guess, but works.我猜不是最好的解决方案,但有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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