1

I am using angular-ui-router in my angular application. I want to make URLs in my application case insensitive. I explored in stack overflow and one of the answers here suggested me to use this code in the app config:

$urlRouterProvider.rule(function ($injector, $location) {
        //what this function returns will be set as the $location.url
        var path = $location.path(), normalized = path.toLowerCase();
        if (path != normalized) {
            //instead of returning a new url string, I'll just change the $location.path directly so I don't have to worry about constructing a new url string and so a new state change is not triggered
            $location.replace().path(normalized);
        }
        // because we've returned nothing, no state change occurs
        //return $location.absUrl(normalized);
    });

However it doesn't work for me and my application returns back to the home page(when trying to alter the case in URL) since my default router page setting is (/Home). When the url changes, I want the code to load the corresponding template and invoke its corresponding controller. What am I doing wrong?

3
  • instaed of $location..replace().path(normalized); use $location.replace().path(normalized); Commented May 20, 2014 at 7:15
  • that's a mistake while copying into question. I've corrected it. Commented May 20, 2014 at 10:06
  • I still have the problem. Can someone help? Commented May 25, 2014 at 14:15

1 Answer 1

0

I know this is an old question but it might still help someone who is facing a similar issue.

Since you are normalizing the URL to lowercase, make sure the URL in your state configurations is also lower case.

For example, this will not work:

$stateProvider.state('state1', { url: '/STATE1' ...

This will work:

$stateProvider.state('state1', { url: '/state1' ...
Sign up to request clarification or add additional context in comments.

1 Comment

URL in state configuration was in lower case itself. But it wasn't working for me.

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.