Named/Child 如果通过输入 url 或刷新进行导航,路由器出口抛出 404

Named/Child router outlets throwing 404 if navigate to by typing in url or refreshing

我正在使用 named/child router-outlet 重新加载动态加载数据到表单中。我遇到的问题是,它只有在我以编程方式导航到路线时才有效:

this.router.navigate([
      '/printers',
      { outlets: { 'form-outlet': [selectedPrinter.id] } },
    ]);

...这很好用,但是如果我尝试复制并粘贴 URL(例如“http://localhost:4200/printers/(form-outlet:119)”)或刷新页面 URL 我在控制台中收到 404 错误:

Failed to load resource: the server responded with a status of 404 (Not Found)

有谁知道为什么会发生这种情况以及如何解决?

通过将 index.html <base href="./"> 更改为 <base href="/"> 而没有 . 来修复它。