【问题标题】:Angular routing error: should only include this file once角度路由错误:应该只包含这个文件一次
【发布时间】:2017-08-19 01:30:08
【问题描述】:

我在玩tutorial Tour of Heroes found here。一切运行,看起来都很好。但是,在我添加从根页面到仪表板和英雄详细信息的路由后,我在控制台中收到以下错误:

Unexpected condition on http://localhost:3000/dashboard: should only include this file once

单击仪表板链接后会看到该错误。 该消息是从该行代码抛出的:

expect(!loadTimeData, 'should only include this file once');

VM1812:155 中。 JS 版本为 V8 5.6.326.50。我使用的 Angular 版本是 4.0.0,在 package.json 中声明:

"dependencies": {
  "@angular/common": "~4.0.0",
  "@angular/compiler": "~4.0.0",
  "@angular/core": "~4.0.0",
  ...
}

dashboard.component.ts

import { Component, OnInit  } from '@angular/core';

import { Hero } from '../heroes/hero';
import { HeroService } from '../model/hero.service';

@Component ({
  selector: 'my-dashboard',
  templateUrl: './html/dashboard.component.html',
  styleUrls: ['./css/app.css'],
})

export class DashboardComponent implements OnInit {

  heroes: Hero[] = [];

  constructor(private heroService: HeroService) { }

  ngOnInit(): void {
    this.heroService.getHeroes()
      .then(heroes => this.heroes = heroes.slice(1, 5));
  }
}

/dashboard 页面链接在 app.component 模板中,如下所示:

<nav>
  <a routerLink="/heroes">Heroes</a><!--another page, also problematic-->
  <a routerLink="/dashboard">Dashboard</a>
</nav>
<router-outlet></router-outlet>

并且路由定义在这样的模块中定义:

@NgModule({
  imports: [ RouterModule.forRoot(
    [
      { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
      { path: 'dashboard',  component: DashboardComponent },
    ]
  ) ],
  //...
})

有人知道这个错误是什么意思,为什么会弹出?

【问题讨论】:

  • 请发布包含您的链接的代码以及路线定义。
  • @banan3'14 你解决了吗?你的浏览器是什么? React Router 也有同样的问题
  • 我没有解决。我的浏览器是 Yandex 57(它基于 Chromium,所以它基本上类似于 Google Chrome)。我尝试在其他浏览器中打开它,但应用程序无法加载(例如,在不是我的默认浏览器的 Safari 5.1.7 中,我只能看到 Loading HeroComponent content here ...)。

标签: javascript angular routing angular-routing


【解决方案1】:

我检查了每个浏览器,似乎它只适用于 Yandex 浏览器。从我的角度来看,该错误需要发送给 Yandex 支持团队。但是,它不会影响最终用户体验或任何功能。我们现在可以放心地忽略它。

PS - Angular 应用程序不适用于旧版 safari (5.1.7),请使用仅适用于 MacOS 或任何其他现代浏览器的最新版 (9-10)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-11
    • 2017-12-13
    • 1970-01-01
    • 1970-01-01
    • 2019-07-07
    • 2020-02-09
    • 2018-02-22
    • 1970-01-01
    相关资源
    最近更新 更多