url 如何直接在 Ionic 4 中打开页面

How to open page directly in Ionic 4 from url

我在 Ionic 4 中有一个项目,当我这样做时 ionic serve 它运行在 localhost:8100/

现在当它加载主页时,URL 是 localhost:8100/home,如果我打开联系人页面,URL 变成 localhost:8100/contact

当我尝试复制上面的 URL 并点击时,它会显示 -

Sorry, this page doesn't exist. Please check the URL or go back a page.

我需要做什么才能让它正常工作?

这通常不应该发生,您对此无能为力。尝试使用 nodejs 将你的 ionic 升级到最新版本,因为我的错误来自于损坏的项目创建。然后在更新后创建一个新项目,它应该会很好。

根据您的评论,发生这种情况是因为您的服务器不支持回退。因此,当您手动输入 url 时,服务器会尝试查找该页面,但由于客户端路由,您的应用程序中只有 index.html

If the app uses the Angular router, you must configure the server to return the application's host page (index.html) when asked for a file that it does not have.

该配置特定于您的服务器或云平台。您可以查看 Angular deployment 了解更多信息。