首页 > 解决方案 > 不调试时无法通过路由访问组件

问题描述

我目前正在开发一个带有 Dot Net Core API 后端的 Angular 单页应用程序,并且在我的应用程序中遇到了路由问题。

在我的 Angular 应用程序中使用“ng-serve”并使用 localhost:4200 访问 SPA 时,我可以访问我的密码重置路由并显示组件。但是,当我运行“ng-build”以在我的 Dot Net Core API 中创建 wwwroot 文件夹并尝试通过地址栏访问路由时,它说在 localhost:38611 或 localhost:44316 中都找不到该页面(SSL )。

我的导航路线的代码如下

export const routes: Routes = [
 { path: 'password-reset', component: UserPasswordResetComponent },
 { path: '', component: HomeComponent },
 {
  path: '',
  runGuardsAndResolvers: 'always',
  canActivate: [AuthenticateGuard],
  children: [
    { path: 'downloads', component: MenuDownloadsComponent },
    { path: 'user-profile', component: UserProfileComponent }
  ]
 },
 {
  path: '',
  runGuardsAndResolvers: 'always',
  canActivate: [ManagerGuard],
  children: [
    { path: 'manager-dashboard', component: DashboardManagerComponent },
    { path: 'history', component: MenuHistoryComponent }
  ]
 },
 {
   path: '',
   runGuardsAndResolvers: 'always',
   canActivate: [AdminGuard],
   children: [
    { path: 'admin-dashboard', component: DashboardAdminComponent },
    { path: 'user-admin', component: MenuAdminUserComponent },
    { path: 'company-admin', component: MenuAdminCompanyComponent },
    { path: 'software-admin', component: MenuAdminSoftwareComponent },
    { path: 'release-admin', component: MenuAdminReleaseComponent },
    { path: 'item-admin', component: MenuAdminItemComponent },
    { path: 'uploads', component: MenuUploadsComponent }
   ]
 },
 { path: '**', redirectTo: '', pathMatch: 'full' }
];

我很困惑为什么它在一个实例中起作用但在其他实例中不起作用,任何帮助将不胜感激。

我将 VS Code 用于我的 Angular(我最近更新到 Angular 10)和 Visual Studio 用于 Dot Net Core(版本 3.1),但我也尝试在 VS Code 中运行它,但无济于事。

标签: c#angular.net-core

解决方案


推荐阅读