首页 > 解决方案 > Angular 路由器阻止对服务器的调用

问题描述

这是我的路由器代码:

const routes: Routes = [
    { path: '', component: IndexComponent},
    { path: 'microservice/:id', component: MicroserviceComponent}
];

我正在尝试通过加载这样的 URL(获取请求)从服务器加载端点

window.open("localhost:8080/api/login", "_self");

但是,如果我在主页(路径'')中执行此操作,它会到达服务器,我可以从服务器端看到它。如果我在microservice/bluh页面中运行此代码,则会显示主页并且不会点击登录端点。

阻止呼叫到服务器的路由是否有问题?

标签: angularangular-router

解决方案


将 pathMatch: 'full' 添加到您的主要组件:

const routes: Routes = [
    { path: '', component: IndexComponent,pathMatch: 'full' },
    { path: 'microservice/:id', component: MicroserviceComponent}
];

推荐阅读