Angular 路由器阻止对服务器的调用

Angular router blocks calls to server

这是我的路由器代码:

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

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

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

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

路由是否有问题导致无法调用服务器?

将路径匹配:'full' 添加到您的主要组件:

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