0

I am beginner in AngularJS and i am trying to remove # symbol from URL and i am using Visual Studio code IDE ,I did below steps for remove # from URL and when i launch Application with HTTP Live server its working and # removed from URL but when i reload page i am getting 404 can some one suggest me please

app.js

var routerApp = angular.module('routerApp', ['ui.router']);

routerApp.config(function ($stateProvider,$locationProvider,$urlRouterProvider) {

    $urlRouterProvider.otherwise('/employeeList');

    $stateProvider

        .state('home', {
            url: '/home',
            templateUrl: 'templates/home.html'
        })
       .state('employeeList', {
            url: '/employeeList',
            templateUrl: 'templates/list_of_employees.html',
            controller: 'EmployeeController'
        })
        $locationProvider.html5Mode(true).hashPrefix('')

});

index.html

<head>
  <base href='/'>
</head>
AbhiRam
  • 2,033
  • 7
  • 41
  • 94

1 Answers1

0

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

Assuming you are using Apache and your index file is index.php or index.html , try adding the following to your .htaccess file to create a rewrite rule.

   <IfModule mod_rewrite.c> 
      RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f 
      RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) /index.php/#/$1 
   </IfModule>
subodhkalika
  • 1,964
  • 1
  • 9
  • 15