我使用RouterModule後不工作,我有這個在我的app.module.ts角2路AOT編譯生成
const appRoutes: Routes = [
{ path: '', redirectTo: 'mainMenu', pathMatch: 'full' },
{ path: 'mainMenu', component: MainComponent,
children: [
{
path: '',
redirectTo: 'products',
pathMatch: 'full'
},
{
path: 'products',
component: ProductsComponent
}
]
},
{ path: 'targeting', component: TargetingComponent }
];
它的作品真的很好,當我在本地測試。/mainMenu/products將我帶到MainComponent幷包含ProductsComponent。和/ targeting將我帶到TargetingComponent。
我建立
ng build --aot
在蒸餾水生成的文件放在服務器上的項目。該頁面會自動重定向到/ mainMenu/products。但是,如果我在URL/mainMenu/products或/ targeting中輸入,則不起作用。我得到GET /mainMenu/products" Error (404): "Not found"
或GET /targeting" Error (404): "Not found"
。所以我認爲這是因爲提前編譯而發生的,這是真的嗎?有什麼我應該做的配置這個工作?
我正在使用npm http-server。
好吧,我創建了上述文件。並將其放在與index.html相同的目錄中。還是一樣。我錯過了其他步驟嗎?它如何自動知道從.htaccess文件中讀取btw? – Eddy
你必須使用Apache並允許AllowOverride – al37350
我使用npm http-server,有什麼想法嗎? – Eddy