1

I am trying to use Angular UI router in my application. When I initialise the UI router instead of getting say, localhost:8000/#/ I get localhost:8000/#!#%2F.

My app.js is as follows:

angular
    .module('quiz',['ngMaterial',
                    'ngMessages',
                    'ngCookies',
                    'ngResource',
                    'quiz.routes'
                    ]).config(function($resourceProvider) {
                                    $resourceProvider.defaults.stripTrailingSlashes = false;
                                    }); 

angular
    .module('quiz.routes',['ui.router']);

In my quiz.routes.js I have:

(function () {
    angular
    .module('quiz.routes')
    .config(config);

    function config($urlRouterProvider,$stateProvider){
        $stateProvider
            .state('register',{
                url: '',
                templateUrl: '/static/templates/register.html'
            });
    }

})();

So instead of the trailing slash I get !#%2F in my URL. Why is this?

4
  • have you injected quize.routes to your main module? Commented Feb 12, 2017 at 16:27
  • Yes, I will edit the code, I forgot to add it here Commented Feb 12, 2017 at 16:31
  • Well, I'm not sure enough to write a answer about this. But I think you need to have a url set, in your case '/'... You would only have a empty url if you're defining a abstract state. Commented Feb 12, 2017 at 16:44
  • I've posted what is a likely cause, however this may not be the full story, and you may have to adjust your routes and links too. Commented Feb 12, 2017 at 17:02

1 Answer 1

3

Assuming that you are using Angular version 1.6, then this is likely because of the changes made to the default hashPrefix which is now set to !. To fix, you need to inject $locationProvider into your module's config block and reset the default hashPrefix back to the empty string.

$locationProvider.hashPrefix('')

This was reported as a bug here, although it turns out that it was by design and changed intentionally.

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

1 Comment

Oh brilliant. I'm on a slow connection right now so didn't see that you had accepted the answer before I commented above. Pleased it worked.

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.