AngularJS routing without the hash '#'

前端 未结 10 776
野性不改
野性不改 2020-11-22 01:40

I\'m learning AngularJS and there\'s one thing that really annoys me.

I use $routeProvider to declare routing rules for my application:

         


        
10条回答
  •  旧巷少年郎
    2020-11-22 02:14

    If you enabled html5mode as others have said, and create an .htaccess file with the following contents (adjust for your needs):

    RewriteEngine   On
    RewriteBase     /
    RewriteCond     %{REQUEST_URI} !^(/index\.php|/img|/js|/css|/robots\.txt|/favicon\.ico)
    RewriteCond     %{REQUEST_FILENAME} !-f
    RewriteCond     %{REQUEST_FILENAME} !-d
    RewriteRule     ./index.html [L]
    

    Users will be directed to the your app when they enter a proper route, and your app will read the route and bring them to the correct "page" within it.

    EDIT: Just make sure not to have any file or directory names conflict with your routes.

提交回复
热议问题