简体   繁体   English

我的 Angular web 应用程序按预期通过按钮进行路由,但是当我在 url 中键入页面路径时,路由不起作用。 托管于 firebase

[英]My Angular web app is routing through buttons as expected, but when I type the page path in the url, routing doesn't work. While hosted on firebase

When I run the program on my localhost, I can navigate through my program using the url, but not when it is hosted on firebase.当我在我的本地主机上运行该程序时,我可以使用 url 浏览我的程序,但当它托管在 firebase 上时则不能。

eg) Typing "www.localhost:4200/home" Takes me home.例如)输入“www.localhost:4200/home”带我回家。

Typing "www.localhost:4200/contact" Takes me to contact page.键入“www.localhost:4200/contact”将我带到联系页面。

BUT

When I host the website on firebase, I can only access it directly:" www.portfoliotest.web.app " and routing through the buttons work, but not when I type "www.portfoliotest.web.app/home" or "www.portfoliotest.web.app/contact" but i get a "Page not found" firebase error instead.当我在 firebase 上托管网站时,我只能直接访问它:“ www.portfoliotest.web.app ”并通过按钮进行路由,但当我键入“www.portfoliotest.web.app/home”或“www”时则不行.portfoliotest.web.app/contact”,但我收到“找不到页面”firebase 错误。

How can I set up my routing so that I can access my pages through the url?如何设置我的路由以便我可以通过 url 访问我的页面?

Thank you.谢谢你。

Your routing isn't your issue: it's how you've set up Firebase.您的路由不是您的问题:这是您设置 Firebase 的方式。

In your firebase.json , you need to redirect all URLs to index.html :在您的firebase.json中,您需要将所有 URL 重定向到index.html

"rewrites": [
  {
    "source": "**",
    "destination": "/index.html"
  }
]

That way, your Angular routing takes precedence over static file service.这样,您的 Angular 路由优先于 static 文件服务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在通过 SendGrid 发送 Email 时在我的标题中添加了 In-Reply-To 和 References,但是它不起作用 - I added In-Reply-To and References in my headers while sending Email through SendGrid, however it doesn't work 当 WiFi 开启时,Android 应用程序无法运行。 (使用 Firebase 和 Admob) - Android app doesn't work while WiFi is on. (With Firebase and Admob) Firebase 添加 web 应用程序不起作用 - 错误 [原因:查找机器人时删除了帐户。 AppIdentity::DELETED] - Firebase adding web app doesn't work - err [Reason: Deleted account when looking up robot. AppIdentity::DELETED] 通过Firebase Cloud Functions访问Firestore时的流量路由 - Traffic routing when accessing Firestore through Firebase Cloud Functions Firebase 撤销下载 URL 不起作用 - Firebase revoking download URL doesn't work firebase 部署和托管 React App 时获取空白页面 - Getting blank page when React App is deployed and hosted by firebase 访问我的 Firebase 托管 web 应用程序(无自定义 URL)后,如何解决“ERR CERT COMMON NAME INVALID”页面? - How do I resolve "ERR CERT COMMON NAME INVALID" page after visiting my Firebase hosting web app (no custom URL)? Google Cloud App Engine 中的 Angular 7 路由不起作用 - Angular 7 Routing in Google Cloud App Engine not working 为什么我的 Vuepress 站点在本地可以运行,但托管在 Firebase 上却不能运行? - Why does my Vuepress site work locally but not when hosted on Firebase? 从 AWS API 网关路由消息到 SQS 关于 URL 路径 - Routing message from AWS API Gateway to SQS regarding URL path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM