1

I want to remove #! from url and I used

$locationProvider.html5Mode(true);

For this and it works but when I refreshes the page it can't be able to find the page and give error.

what should I do for this?

Index.html

<!DOCTYPE html>
<html dir="ltr" lang="en" ng-app="myapp">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />

<head>
    <meta charset="UTF-8" />

    <meta name="viewport" content="width=device-width, initial-scale=1">


    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <base href="/">
</head>

    <body class="product-product-82 responsive full default layout_2">

    <script type="text/javascript" src="bower_components/angular/angular.js"></script>
   <script type="text/javascript" src="app.js"></script>
<script type="text/javascript" src="controllers/config.js"></script>
<script type="text/javascript" src="controllers/productCtrl.js"></script>
<script type="text/javascript" src="controllers/menuCtrl.js"></script>
    <page-loader flag="isLoading"></page-loader>
    <div ui-view="layout"></div>

</body>

</html>

config file for routing

var app = angular.module('myapp');

app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function($stateProvider, $urlRouterProvider, $locationProvider) {
    $urlRouterProvider.otherwise('/');

    $stateProvider
        .state('productpagelayout', {
            abstract: true,
            views: {
                layout: {
                    templateUrl: 'template/layout/productpagelayout .html',
                },
                controller : 'productCtrl'
            }
        })
        .state('landing', {
            url: '/',
            templateUrl: 'template/landing/mainpages.html',
            controller: 'menuCtrl',
            parent: 'productpagelayout',
        })
        .state('home', {
            url: '/home',
            templateUrl: 'template/landing/landing.html',
            controller: 'menuCtrl',
            parent: 'productpagelayout',
        })
        .state('category2',{
            url: '/c/:name1/:name2',
            templateUrl: 'template/product/productsgridpage.html',
            controller: 'productCtrl',
            parent: 'productpagelayout'
        })
     $locationProvider.html5Mode(true);
}])

app.js

var app = angular.module('myapp', ['ui.router', 
  'rzModule', 
  'ngCookies', 
  'ui.bootstrap', 
  'ngSanitize',

]);
6
  • I think you can not remove #! from url because it is default url pattern in angular js. Hence on page refresh it's giving you an error. Commented Aug 23, 2017 at 13:18
  • Possible duplicate of Removing the fragment identifier from AngularJS urls (# symbol) Commented Aug 23, 2017 at 13:18
  • Possible duplicate of $location hash prefix Commented Aug 23, 2017 at 13:18
  • Please atleast read my question I removed #! from url but on refreshing it gives error, Do any one have solution for this Commented Aug 23, 2017 at 14:11
  • 1
    I had updated my code above Commented Aug 24, 2017 at 13:07

1 Answer 1

1

You can try and use:

app.config(['$locationProvider', function($locationProvider) {
  $locationProvider.hashPrefix('');
}]);
Sign up to request clarification or add additional context in comments.

1 Comment

I had used it but the problem is that when I refreshes the page it doesnot go on that page and gives error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.