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>
8
  • Check this stackoverflow.com/questions/14771091/… Commented Dec 25, 2018 at 6:16
  • Ahmed Ghoniem i did same i n my above code please che ck Commented Dec 25, 2018 at 6:19
  • remove .hashPrefix('') Just keep $locationProvider.html5Mode(true); Commented Dec 25, 2018 at 6:52
  • That's not problem even when remove it's not working Commented Dec 25, 2018 at 6:53
  • I am using vs code I think we have to set something in web.config file but in vs code there is no web.config file Commented Dec 25, 2018 at 6:54

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

8 Comments

Where should I use this code?
you need to create a .htaccess file in your project folder
How can I create ?
can we create this in vsCode?
create a new file with file named .htaccess
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.