【问题标题】:routing in angular 12角度 12 中的路由
【发布时间】:2021-10-15 19:38:05
【问题描述】:

我在 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 { }

我已经在开发服务器中部署了我的应用程序。网址看起来像这样

https://myDomain/MyApplicationFolder/Login

登录页面完美呈现。所有路由工作正常。我唯一担心的是

如果我输入

https://myDomain/MyApplicationFolder/  I get forbidden error.

无论如何我会被重定向到

https://myDomain/MyApplicationFolder/home 

如果有人输入

https://myDomain/MyApplicationFolder/

【问题讨论】:

  • 请在 index.html 的 <base href="/MyApplicationFolder"> 标签中定义您的应用程序文件夹路径

标签: angular routes


【解决方案1】:

这似乎更多是 IIS 的问题,你应该看看你是如何配置你的服务器的。

匿名身份验证是否开启?

如果您为此配置了 URL 重写,您可能会在 IIS 中将根路径重写为 /Home。

【讨论】:

  • "在 IIS 中将 h 的 URL 重写为 /Home。"成功了。谢谢
猜你喜欢
  • 2017-05-06
  • 2017-02-10
  • 2015-06-13
  • 2016-04-07
  • 2017-04-23
  • 1970-01-01
  • 1970-01-01
  • 2018-10-12
  • 2015-12-29
相关资源
最近更新 更多