0

I have the following angular route:

            $routeProvider.when('/sites/:var1/:var?/something/:year?/:month?/', {
                templateUrl: 'path-to-template.html,
                controller: 'PageController'
            });

             $locationProvider.html5Mode(true);

The problem is that when i hit the route http://www.somesite.com/sites/category/something/2014/10/ Angular tries to match the optional named groups and in the end transforms the url to http://www.somesite.com/sites/category/%3F/something/2014%3F/10%3F/ and redirects me to the that path.

Does anyone knows of any good reason why the optional path would be replaces by /?/ (encoded: %3F)?

Any help is greatly appreciated. Thank you

EDIT

What happens is that router in angular replaces the url to match exactly what you provide in the .when, in terms of / ? (and not sure what else). So if it finds a route matching .when but missing either / or ? it just appends it and refreshes (angular refresh) and then apparently url encodes it. (??? :o)

user3638565
  • 55
  • 1
  • 6

1 Answers1

0

I've narrowed it down to the trailing slash. Using:

'/sites/:var1/:var?/something/:year?/:month?/'

together with:

http://www.somesite.com/sites/category/something/2014/10/

resolved correctly, as does removing the slash from both. In fact, adding any optional named group to the url causes the route to be slash dependent. As to why this is happening...

Abraham Chan
  • 629
  • 3
  • 12
  • If i remove the trailing slash form the route it works. But that is not the problem because if i do that the inverse has a problem. What i am trying to understand is why a route without optional named groups i.e. '/something/something' (with or without trailing slash) works either way but not routes with optional named groups? – user3638565 Sep 26 '14 at 12:43