AngularJS HTML5Mode

安稳与你 提交于 2019-12-17 19:40:58

问题


I am using HTML5 mode in my angular app to turn off hashbangs and that is because I am going to be providing URLs for my users like:

http://myapp.com/nicklewis

Rather than:

http://myapp.com#/nicklewis

The latter works but it isn't ideal for vanity URLs.

So short of writing my own NodeJS app to resolve this issue, is there anything in Firebase I could make use of or not?


回答1:


Firebase just had a recent update that included this functionality. You can use it like so in your firebase.json:

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

This is the code sample used in their docs and will send any directory or file that is not found back to index.html.

It's important to note that you will need to update your firebase deployment tools to version 1.1.0 or higher for this to work:

$ npm update -g firebase-tools

You may need to use 'sudo' with this depending on your permissions.

You can read the documentation here: https://www.firebase.com/docs/hosting/guide/url-redirects-rewrites.html

You can read about updating firebase tools here: https://www.firebase.com/docs/hosting/guide/command-line-tool.html



来源:https://stackoverflow.com/questions/24206362/angularjs-html5mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!