【发布时间】:2016-09-28 04:44:16
【问题描述】:
我遵循了 Angular2 的路由教程。但是,我现在遇到了一个我似乎无法修复的奇怪错误:
127.0.0.1/:21 错误:(SystemJS) 无法解析 provideLocationStrategy 的所有参数:(PlatformLocation, ?, Token_ROUTER_CONFIGURATION)。
app.routing.ts
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {MyComponent} from "./myComponent/myComponent.component";
const appRoutes: Routes = [
{ path: '', component: MyComponent},
{ path: '**', component: MyComponent}
];
//
//export const appRoutingProviders: any[] = [
//
//];
//
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { routing, appRoutingProviders } from './app.routing';
import { AppComponent } from './app.component';
import {MyComponent} from "./myComponent/myComponent.component";
@NgModule({
imports: [
BrowserModule,
routing
],
declarations: [
AppComponent,
MyComponent
],
providers: [
//appRoutingProviders
],
bootstrap: [
AppComponent
]
})
export class AppModule { }
在文档中,他们从 app.routing.ts 导出 appRoutingProviders,但在教程中却没有,所以我将其省略了。结果是一样的,反正它似乎只是一个空数组。
什么可能导致这个错误?
【问题讨论】:
-
index.html 页面上有
<base href="/">和<router-outlet></router-outlet>