我使用路由角色2與打字稿。路徑:「**」未找到頁面
在主index.html
我添加<base href="">
,不<base href="/">
,因爲我需要爲我的項目的特殊路線,一切工作正常,但我有一些問題,找不到網頁。這裏是我的app.route.ts
的一部分:
const appRoutes: Routes = [
{ component: LaskComponent, path: "table_per" },
{ component: LaskComponent, path: "table_per/:id" },
{ component: DashboardComponent, path: "dashboard" },
{ component: LoginComponent, path: "login" },
{ path: "", pathMatch: "full", redirectTo: "login" },
{ component: HomeComponent, path: "home" },
{ component: NotFoundComponent, path: "not_found" },
{ path: "**", redirectTo: "not_found" },
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
這是NotFoundComponent
:
import { Component } from "@angular/core";
@Component({
template: '
<div class="container">
<h1>Not found page</h1>
</div>',
})
export class NotFoundComponent {};
當我開始localhost
在Chrome瀏覽器項目,我重定向到localhost/login
,一切正常,但是當我檢查一個沒有找到的頁面,例如localhost/sxvknb
,我得到這個頁面localhost/sxvknb/login
並再次以登錄形式重定向。問題是什麼?也許有
{ path: "**", redirectTo: "not_found" }
啓動項目中,我可以用3開始部署:
可以提供'APP_BASE_HREF'而不是' 'http://stackoverflow.com/q uestions/34535163/angular-2-router-no-base-href-set/34535256#34535256 –