3

My url: eDemo/admin/test/list/#/list

I want: eDemo/admin/test/list

js:

var serviceBase ="http://admin-pc/eDemo/admin/test/";
function config($routeProvider, $locationProvider) {

    $routeProvider
        .when('/add', {
            controller: 'addController',
            templateUrl: serviceBase + 'add',
            controllerAs: 'vm',
        })
        .when('/edit', {
            controller: 'editController',
            templateUrl: serviceBase + 'edit',
            controllerAs: 'vm',
        })


        .otherwise({ redirectTo : 'list' });
}

html:

<div class='ng-view'></div>
2
  • 4
    scotch.io/tutorials/… Commented Mar 9, 2016 at 7:07
  • 1
    @DeepKakkar .. you better do copy the main part of the link code and post in answer section .. It's will remove dependency of that link and the question will have it's answer here .. Commented Mar 9, 2016 at 7:31

3 Answers 3

2

You just need to add html5Mode(true) in your route provider configuration. Make sure that you are passing the parameter $locationProvider on config function as an argument.

here us the sample js code:

var serviceBase ="http://admin-pc/eDemo/admin/test/";
app.config(['$routeProvider','$locationProvider',
     function ($routeProvider,$locationProvider) {

    $routeProvider
        .when('/add', {
            controller: 'addController',
            templateUrl: serviceBase + 'add',
            controllerAs: 'vm',
        })
        .when('/edit', {
            controller: 'editController',
            templateUrl: serviceBase + 'edit',
            controllerAs: 'vm',
        })


        .otherwise({ redirectTo : 'list' });

         $locationProvider.html5Mode(true);

}

And your HTML should looks like below :

<div class='ng-view'>
 <base href="<?=url('/').'/'?>">
</div>

Also Keep in mind that never pass # in anykind of url like you redirecting , you submitting form through AJAX or anywhere.

Sign up to request clarification or add additional context in comments.

Comments

1

At the End of route use:

 $locationProvider.html5Mode(true);

This should be:

var serviceBase ="http://admin-pc/eDemo/admin/test/";
function config($routeProvider, $locationProvider) {

$routeProvider
    .when('/add', {
        controller: 'addController',
        templateUrl: serviceBase + 'add',
        controllerAs: 'vm',
    })
    .when('/edit', {
        controller: 'editController',
        templateUrl: serviceBase + 'edit',
        controllerAs: 'vm',
    })
    $locationProvider.html5Mode(true);

    }

In View File:

<head>
    <meta charset="utf-8">

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

Comments

1

you can use the $locationProvider like this

$locationProvider.html5Mode({
  enabled: true,
  requireBase: false
});

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.