angular 12 中的路由
routing in angular 12
我在 VSCode 和 Web Api 2 中使用了 angular 12 来开发我的应用程序。
我的路线是这样的
const routes: Routes = [
{ path: '', component: HomeComponent, canActivate: [AuthGuard] },
{ path: 'home', component: HomeComponent, canActivate: [AuthGuard] },
{ path: 'login', component: LoginComponent },
.......// other routes in the application
];
@NgModule({
imports: [RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' })],
exports: [RouterModule]
})
export class AppRoutingModule { }
我已经在开发服务器中部署了我的应用程序。 url 看起来像这样
https://myDomain/MyApplicationFolder/Login
登录页面完美呈现。所有路由工作正常。我唯一担心的是
如果我输入
https://myDomain/MyApplicationFolder/ I get forbidden error.
无论如何我都会被重定向到
https://myDomain/MyApplicationFolder/home
如果有人输入
https://myDomain/MyApplicationFolder/
这似乎更多是 IIS 的问题,您应该查看您是如何配置服务器的。
是否开启匿名认证?
如果您为此配置了 URL 重写,您可以在 IIS 中将根路径重写为 /Home。
我在 VSCode 和 Web Api 2 中使用了 angular 12 来开发我的应用程序。
我的路线是这样的
const routes: Routes = [
{ path: '', component: HomeComponent, canActivate: [AuthGuard] },
{ path: 'home', component: HomeComponent, canActivate: [AuthGuard] },
{ path: 'login', component: LoginComponent },
.......// other routes in the application
];
@NgModule({
imports: [RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' })],
exports: [RouterModule]
})
export class AppRoutingModule { }
我已经在开发服务器中部署了我的应用程序。 url 看起来像这样
https://myDomain/MyApplicationFolder/Login
登录页面完美呈现。所有路由工作正常。我唯一担心的是
如果我输入
https://myDomain/MyApplicationFolder/ I get forbidden error.
无论如何我都会被重定向到
https://myDomain/MyApplicationFolder/home
如果有人输入
https://myDomain/MyApplicationFolder/
这似乎更多是 IIS 的问题,您应该查看您是如何配置服务器的。
是否开启匿名认证?
如果您为此配置了 URL 重写,您可以在 IIS 中将根路径重写为 /Home。