[英]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.