我的应用程序中的路由存在问题。在我的本地一切正常,但在服务器上却不行。该程序有以下路线:
const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'thankyou', component: ThankyouComponent },
{ path: 'home', component: UserHomeComponent, canActivate: [AuthGuard] },
{ path: 'publish', component: PublishComponent, canActivate: [AuthGuard] },
{ path: '**', component: PageNotFoundComponent }
];
root route
总是有效的。
如果在我的电脑上我直接发送请求,例如路由:
http://localhost:4200/publish
假设我已经登录,加载它没有问题。但是,如果在服务器中使用该路由执行该路由:
http://myserver/mypath/dist/publish
它没有找到路线。
我也修改了 index.html,以便在服务器上执行。
<base href="/">
经过<base href="/mypath/dist/">
如果我使用指令通过模板 html 执行该路由
routerLink="/publish"
它工作正常。
有谁知道为什么会这样?