Question

I've setted up a simple pagination url like this:

.when('/users/:offset/:filter/:keywords',{
          templateUrl:'views/users/index.html',
          controller:'Users',
          reloadOnSearch:false
        }) 
.otherwise({
          redirectTo:'/'
        });

now if i browse site.co/users/5/1/heykeyword it works

BUT if i browse site.co/users/5/1 i get redirected to /

what's wrong?

Shouldn't routeParams be dynamic !?!

Was it helpful?

Solution

The problem is that what you have written includes a must arguments,

you can achieve it by adding the 'keywords' as optional (by adding a question mark):

.when('/users/:offset/:filter/:keywords?',{
          templateUrl:'views/users/index.html',
          controller:'Users',
          reloadOnSearch:false
        }) 
.otherwise({
          redirectTo:'/'
        });

the offset & filter are required, but now the keywords parameters is optional.

For more info: https://docs.angularjs.org/api/ngRoute/provider/$routeProvider

From angularjs documentation:

path can contain optional named groups with a question mark: e.g.:name?.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top