简体   繁体   中英

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.

eg) Typing "www.localhost:4200/home" Takes me home.

Typing "www.localhost:4200/contact" Takes me to contact page.

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.

How can I set up my routing so that I can access my pages through the url?

Thank you.

Your routing isn't your issue: it's how you've set up Firebase.

In your firebase.json , you need to redirect all URLs to index.html :

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

That way, your Angular routing takes precedence over static file service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM