【发布时间】: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