AngularJS HTML5Mode

Nic*_*wis 9 pushstate angularjs firebase

我在我的角应用程序中使用HTML5模式来关闭hashbangs,这是因为我将为我的用户提供以下URL:

http://myapp.com/nicklewis

而不是:

HTTP://myapp.com#/nicklewis

后者有效,但它不适合虚荣URL.

由于没有编写我自己的NodeJS应用程序来解决这个问题,Firebase中是否可以使用或不使用?

小智 16

Firebase刚刚发布了包含此功能的最新更新.您可以在firebase.json中使用它:

"rewrites": [ {
    "source": "**",
    "destination": "/index.html"
} ]
Run Code Online (Sandbox Code Playgroud)

这是他们的文档中使用的代码示例,并将任何未找到的目录或文件发送回index.html.

请务必注意,您需要将firebase部署工具更新到1.1.0或更高版本才能使其正常工作:

$ npm update -g firebase-tools
Run Code Online (Sandbox Code Playgroud)

根据您的权限,您可能需要使用"sudo".

您可以在此处阅读文档:https://www.firebase.com/docs/hosting/guide/url-redirects-rewrites.html

您可以在此处阅读有关更新firebase工具的信息:https://www.firebase.com/docs/hosting/guide/command-line-tool.html

  • @JohnAndrews这意味着所有与现有文件不匹配的url将被路由到index.html,其中angular将获取它们并为您的应用程序运行适当的路由(如果存在).基本上他回答了你的问题. (2认同)