Angular HTML5 mode, router going to otherwise state on page reload

后端 未结 1 1445
抹茶落季
抹茶落季 2021-01-11 11:12

I am trying to remove hash tag from my website. I have achieved it by following code.

$locationProvider.html5Mode(true);

As well as added b

相关标签:
1条回答
  • 2021-01-11 12:00

    In order to support reloading of HTML5 mode route URLs, you need to implement server-side URL rewriting to direct non-file requests (that is, requests that aren't explicitly for an existing file) to your index file, typically index.html.

    From the documentation

    Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html).

    Your rewrite rule should not have any # in the destination URL. Instead, use this

    RewriteEngine on
    
    # Don't rewrite files
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]
    
    # Rewrite everything else to index.html to allow html5 state links
    RewriteRule ^ index.php [L]
    

    Source ~ https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

    Also, there's no need to set RewriteBase.

    0 讨论(0)
提交回复
热议问题