Angular 应用程序路由工作,但只能从内部导航,而不是浏览器地址栏

Angular 应用程序路由工作,但只能从内部导航,而不是浏览器地址栏,angular,angular-routing,angular-router,Angular,Angular Routing,Angular Router,我已经建立了一个有路由模块的angular 11应用程序。如果你通过访问域url启动应用程序,它将做正确的事情并转到“仪表板”路径。一旦到了那里,我可以使用一个有很多链接的菜单来点击,应用程序就会导航到它应该去的地方 http://localhost:4200->将我带到“仪表板”路径 http://localhost:4200/dashboard->将我带到“仪表板”路径 但我无法在浏览器地址栏中键入另一个有效路径(我可以通过routerlink或代码nvagation访问),如下所示: ht

我已经建立了一个有路由模块的angular 11应用程序。如果你通过访问域url启动应用程序,它将做正确的事情并转到“仪表板”路径。一旦到了那里,我可以使用一个有很多链接的菜单来点击,应用程序就会导航到它应该去的地方

http://localhost:4200
->将我带到“仪表板”路径

http://localhost:4200/dashboard
->将我带到“仪表板”路径

但我无法在浏览器地址栏中键入另一个有效路径(我可以通过routerlink或代码nvagation访问),如下所示:

http://localhost:4200/management/user-管理
这是通过内部应用程序导航实现的,但是,如果我在浏览器地址栏中键入上述内容,我将无法到达那里,就好像我键入了
http://localhost:4200/dashboard

路由器代码如下:

const routes: Routes = [
  {
    path: 'dashboard',
    canActivate: [AuthenticationGuard],
    component: fromCore.DashboardComponent
  },
  {
    path: 'management',
    loadChildren: () => import('./management/management.module').then(m => m.ManagementModule),
    canLoad: [AuthenticationGuard]
  },
  {
    path: 'inventory',
    loadChildren: () => import('./inventory/inventory.module').then(m => m.InventoryModule),
    canLoad: [AuthenticationGuard]
  },
  {
    path: '',
    redirectTo: 'dashboard',
    pathMatch: 'full'
  }
];
管理模块代码:

const routes: Routes = [{
    path: '',
    component: fromContainers.ManagementComponent,
    children: [
        {
            path: 'user-management',
            component: fromContainers.UserManagementComponent
        },
        {
            path: 'create',
            component: fromContainers.UserCreateComponent
        },
        {
            path: 'edit/:id',
            component: fromContainers.UserEditComponent,
            canActivate: [fromGuards.UserExistsGuard]
        },
        {
            path: 'change-password/:id',
            component: fromContainers.ChangePasswordComponent,
            canActivate: [fromGuards.UserExistsGuard]
        } 
    ]}
];
我做错了什么

回答


以上这些都没有错。我的问题是,我忘记了我有一个ngrx效果,我是从AppComponent(启动组件)运行的。它发送了一个动作,触发了一个总是导航到仪表板的效果。我现在已经确定效果符合预期的路径。

我不是一个棱角分明的人,但在我身上也发生了类似的事情

我的解决方案是(适应您的url)键入如下内容:

http://localhost:4200/dashboard/management/user-management

也许值得一试。

你试过使用散列定位策略吗?@sofa_maniac,不,不能说我理解它。但这真的不应该起作用吗?我会调查一下……也许
可以加载
失败?你能在StackBlitz演示中复制这个问题吗?所以我已经解决了我的问题。这真的相当于一只手不知道另一只手在做什么。。。我将用答案编辑我的问题。因为我懒得加载模块,而且结构不适合该站点,所以我不会尝试此操作。@Irv Lennert,我的意思是在运行开发服务器()后,在本地浏览器中键入该url,而不更改代码中的任何行。并验证是否可以通过这种方式访问该用户管理子页面。。如果您在
http://localhost:4200/dashboard/management/user-管理
,但不在
http://localhost:4200/management/user-管理
,然后它会提示您代码中存在某种子目录问题…谢谢,我已发现问题,我将更新我的问题。非常感谢您的努力和时间!