【问题标题】:Page not loading when redirected, but when back button clicked displays the page for a sec and navigates to previous page重定向时页面未加载,但单击后退按钮时会显示页面一秒钟并导航到上一页
【发布时间】:2019-02-19 06:33:21
【问题描述】:

我正在使用 Angular 2,当我尝试单击链接时,页面未加载,但加载栏继续。 数据和 html 未显示在页面中。当我单击后退按钮加载上一页时,要重定向的页面加载或几秒钟,然后返回初始页面。浏览控制台和服务器控制台中没有显示错误。

编辑:我使用 RouteComponent 来路由页面。相同的链接似乎适用于其他不同的屏幕,但在这个特定的场景中,我看到了一个需要修复的问题。当我尝试调试时,我可以看到我能够加载的组件有数据流入并且不会在任何时候中断以引发错误。

  myRoutes : Routes = [
      { path: 'displayAuthentic/:authId', component: DisplayAuthenticComponent },
    ];

点击链接时导航,

 navigateToAuthDisplay(eventObj: any) {
           this.authId = eventObj.data.authId;
           this.router.navigate(['./displayAuthentic', this.authId]);
 }

这里的任何指针都可以通过这个..

【问题讨论】:

  • 你能发布一些你的代码吗?您是否使用 *ngIf 语句来提高屏幕的可见性?如果您通过等待来自服务器的数据来驱动它,请查看开发工具中的网络选项卡,以确保您得到正确的数据。
  • 我们可以查看您的路由文件吗?
  • 是的,我正在通过 *ngIf 显示可见性。 @thenolin
  • @Exterminator 无法添加路由文件,所以只显示路由
  • 添加整个文件代码

标签: html angular


【解决方案1】:

关于

当我尝试点击链接时,页面没有加载,但加载栏继续...

我不确定,因为没有您的代码很难弄清楚,但在我看来,您的路线可能配置不正确。如果您的链接中的路由是/myRoute,请确保您的路由变量中有app-routing.module.ts,您有该路由的条目

var routes = [
  {
    path: 'myRoute',
    component: MyRouteComponent
  },
...

还要确保你使用了 routerLink:

<a  routerLink="/myRoute"> link</a>

编辑

记得在你的 index.html 中添加这个头

<head>
  <base href="/">
 other css and jquery ...
</head>

【讨论】:

  • 在我的情况下,我不能在此处使用 routerLink,因为当我从一行中选择数据时,我正在使用 ag-grid 来导航项目。相反,我为该特定 Column 声明了一个单独的 columnRenderer 以使其重定向。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-31
相关资源
最近更新 更多