简体   繁体   English

Angular9 router.navigate

[英]Angular9 router.navigate

If the website was enabled on the old browser, my goal is to redirect the page to one with information about it.如果该网站在旧浏览器上启用,我的目标是将页面重定向到包含相关信息的页面。 For this I use the ngx-device-detector package.为此,我使用 ngx-device-detector 包。 And for redirect I am using this.router.navigate which is not working.对于重定向,我使用的 this.router.navigate 不起作用。 Does anyone know why url is not replaced?有谁知道为什么 url 没有被替换? Even though the condition is met, nothing happens.即使满足条件,也不会发生任何事情。

 if(this.browserName === 'Chrome' && this.browserVersion < 83) {
      this.router.navigate(['/pages/unsupported-browsers-component'])
    }
  }

This is part of routing module file这是路由模块文件的一部分

    {
      path: 'pages/unsupported-browsers-component',
      component: UnsupportedBrowsersComponent,
    },

The Navigate function needs to have a pathname without a slash at the start, or you can simply use the path too with slash giving the absolute or relative URL to your component in the NaviagteUrl method. Navigate 函数需要有一个开头不带斜杠的路径名,或者您也可以简单地使用该路径,并在 NaviagteUrl 方法中为您的组件提供绝对或相对 URL。 Refer link: angular.io/api/router/Router#navigate参考链接: angular.io/api/router/Router#navigate

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

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