AngularJs Page Refresh Issue after removed hash

时间:2018-02-03 09:56:16

标签: javascript angularjs .htaccess

Index.html

<!DOCTYPE html>
<html lang="en" ng-app="echo">
    <head>
        <base href="/">
        // Other JS and CSS File
    </head>
    <body>
       <div ng-view></div>
    </body>
</html>

myapp.js

    myapp
  .config(function ($routeProvider, $locationProvider) {
    $routeProvider

    .when('/', {
        templateUrl : 'pages/studies.html',
        controller  : 'listStudyController'
    })
    .when('/dashboard', {
        templateUrl : 'pages/dashboard.html',
        controller  : 'mainController'
    })

    .when('/profile', {
        templateUrl : 'pages/profile.html',
        controller  : 'mainController'
    })
    .otherwise({
        redirectTo: '/'
    });

    //check browser support
    $locationProvider.html5Mode({
        enabled:true,
        requireBase:true
    });
});

.htaccess

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^(.*) /index.html [NC,L]

Note:
- Removed hash tag from url successfully.
- When I reloading page It display error.

Not Found
The requested URL /profile was not found on this server.

1 个答案:

答案 0 :(得分:1)

第1步: 编辑“httpd-vhosts.conf”
第2步: 设置

{{1}}

AllowOverride All 解决了我的问题。