我有我的Angular 2應用程序(最新完整版本不是RC或測試版),其設置與教程(https://angular.io/docs/ts/latest/guide/router.html)上的結構相同。當我把無法在Angular 2中獲得路由工作
<base href="/" />
在我的index.html我得到404錯誤以下:
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
而此行產生錯誤「的JavaScript運行時錯誤:「系統未定義」 System.import('app')。catch(function(err){console.error(err);});
如果我刪除了基本標記,上面的代碼都很好,但是我得到了「沒有基礎href集合,請爲APP_BASE_HREF標記提供一個值或向文檔添加一個基本元素。
如果我改變爲基本href,以
<base href="app" />
,我沒有得到上面任何404錯誤,要麼,但我得到的錯誤「未處理的承諾拒絕:不能匹配任何路線:」
以下是我的app.routing.ts:
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { BatteriesComponent } from './batteries/batteries.component';
import { CabinetsComponent } from './cabinets/cabinets.component';
import { RacksComponent } from './racks/racks.component';
import { ReportsComponent } from './reports/reports.component';
const appRoutes: Routes = [
{
path: '',
redirectTo: './app/batteries/batteries',
pathMatch: 'full'
},
{ path: 'batteries', component: BatteriesComponent },
{ path: 'cabinets', component: CabinetsComponent },
{ path: 'racks', component: RacksComponent },
{ path: 'reports', component: ReportsComponent }
];
export const appRoutingProviders: any[] = [
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
請幫忙。
謝謝
謝謝尼科。我不得不把「/ MyAppName /」作爲Base的href。 – LanceM
標記爲答案,如果它幫助你!謝謝!! – Nico