编辑 这里是我的plunker:plnkr.co/edit/qMBc5j62jQoBJLsFYgr4?p=preview角2 - 路由器的实例化过程中的错误 - (路由器出口 - >路由器)
我使用的是打字稿。
,我发现了以下错误:
Error during instantiation of Router! (RouterLink -> Router). and (RouterOutlet -> Router)
我试图在这个论坛对于这个问题,包括增加/在index.html
改变<base href="/">
或添加APP_BASE_HREF
来引导不同的解决方案。
我一直在使用官方的Angular Plunker教程http://plnkr.co/edit/d8pewJf9kVqD3kTSvQmK?p=preview,它工作正常的代码。
我app.component.ts如下所示:
import { Component } from 'angular2/core';
import {LandingComponent} from './landing.component';
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router';
@Component({
selector: 'my-app',
template: `
<h1>Hello</h1>
<h1>{{title}}</h1>
<nav>
<a [routerLink]="['Landing']">Heroes</a>
</nav>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES],
providers: [ROUTER_PROVIDERS]
})
@RouteConfig({
{
path: '/landing',
name: 'Landing',
component: LandingComponent,
useAsDefault: true
}
})
export class AppComponent {
title = 'Win Free!';
}
main.ts
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent);
的index.html
<html>
<head>
<script>document.write('<base href="' + document.location + '" />'); </script>
<title>Angular 2 QuickStart</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- 1. Load libraries -->
<!-- IE required polyfills, in this exact order -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.0/es6-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.20/system-polyfills.js"></script>
<script src="https://npmcdn.com/[email protected]/es6/dev/src/testing/shims_for_IE.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.12/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://npmcdn.com/[email protected]/lib/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.12/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.12/angular2.dev.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.12/router.dev.js"></script>
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true },
packages: {'app': {defaultExtension: 'ts'}}
});
System.import('app/main')
.then(null, console.error.bind(console));
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
谢谢。
几乎evey的东西似乎没事。你有你的代码淹没吗? – micronyks
你的plnkr工作正常,你的plnkr错误在哪里? –
@PardeepJain。那不是他的闯入者。他正在使用它作为参考。 – micronyks