我使用路由角色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 –