简体   繁体   中英

How to avoid routing changes when deploying angular app?

When running my Angular app locally I can go to for example localhost:4200/login. When I deploy my Angular app however when I go to website.com/login, I get "The requested URL /login was not found on this server". My app is deployed to a Google Cloud appengine.

When I add "useHash: true" to my RouterModule. It works fine, so website.com/#/login works, however this seems counterintuitive since when someone would fill in the url themselves I would assume that they would fill in website.com/login, which would redirect them again to the not found on this server.

How can I avoid using this "useHash:true" and have my routing the same as being locally?

I assume your app.yaml would look something like this:

handlers:
  - url: /
    upload: /index.html
    static_files: /index.html
    secure: always

now when you try to open the URL /login/ , there's no route for it in app.yaml , which is why it returns you 404. So the useHash directive is the only solution you have here.

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