Angular 将localhost:4200导航到404页

Angular 将localhost:4200导航到404页,angular,angular-ui-router,Angular,Angular Ui Router,我们希望根localhost:4200(或部署的根URL,如myApp.com)导航到404。该应用程序设计为仅具有/home/id/anotherID,因为id和anotherID将在后端使用。我尝试了{path:'',ccomponent:ErrorPageComponent}和 {path:'**',component:ErrorPageComponent},。我似乎无法将根url转到404页面。目前,我们有以下路线: { path: 'home/:rmId/:leadId',

我们希望根
localhost:4200
(或部署的根URL,如
myApp.com
)导航到404。该应用程序设计为仅具有
/home/id/anotherID
,因为
id
anotherID
将在后端使用。我尝试了
{path:'',ccomponent:ErrorPageComponent}
{path:'**',component:ErrorPageComponent},
。我似乎无法将根url转到404页面。目前,我们有以下路线:

  {
    path: 'home/:rmId/:leadId',
    canActivate: [SSOAuthGuard],
    component: ScreenComponent,
  },

  {
    path: '',
    component: ErrorPageComponent
  },

  {
    path: '**',
    component: ErrorPageComponent

  },

谢谢

要仅以根url为目标,您应该使用
pathMatch='full'
。 你试过了吗?

试一下
{路径:'**',组件:NotfoundComponent,路径匹配:'前缀'},


另外,将此作为您的最后一个条目。请确保项目已编译且路由正在运行。

请尝试以下第二种方法:
{path:'',组件:ErrorPageComponent,路径匹配:'full'},
尝试删除
{path:'',组件:ErrorPageComponent}
行。我刚刚创建了一个新的应用程序,它只在
{path:'',component:ErrorPageComponent}
上正常工作。我对这个有点困惑,你删除了
{path:'',component:ErrorPageComponent}
,然后通过重新添加它来让它工作?你是对的,对不起。我删除了
{path:'**',component:ErrorPageComponent}
行。谢谢你发现了!是的,
localhost:4200
没有进入404页面。哼,控制台中有错误吗?您正在声明组件吗?
localhost:4200/
将正常工作。尝试将`{path:'**',component:ErrorPageComponent,pathMatch:'prefix'}`作为我的最后一项。应用程序正常运行,没有控制台错误。仍然转到ScreenComponent。然后猜测:-您确定您在Init上未找到的组件或Constructor没有重定向回ScreenComponent吗?应用程序使用的路线是否完全复制到您的问题中?你确定你的应用程序已更新到新路线吗?(在运行ng serve的控制台中,看不到错误消息?)如果重新启动应用程序会发生什么?如果在init上检查Screencomponent中的电流,会发生什么?你能提供你的问题的复制品吗?