簡體   English   中英

角度路由錯誤:應該只包含此文件一次

[英]Angular routing error: should only include this file once

我正在玩這里的英雄之旅教程 一切都運行,看起來很好。 但是,在我從根頁面添加路由到儀表板和英雄的詳細信息后,我在控制台中收到以下錯誤:

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 },
    ]
  ) ],
  //...
})

任何人都知道這個錯誤意味着什么以及它彈出的原因?

我檢查過每個瀏覽器,似乎只適用於Yandex瀏覽器。 從我的角度來看,需要將該bug發送給Yandex支持團隊。 但是,它不會影響最終用戶體驗或任何功能。 我們現在可以放心地忽略它。

PS - 角度應用程序不適用於舊的Safari(5.1.7),使用最新的(9-10),僅適用於MacOS或任何其他現代瀏覽器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM