bialasikk
bialasikk

Reputation: 1065

Parameters in URL using Angular's UI-Router, issue with .otherwise

I want to search on my page. Actually, my code is

$stateProvider
  .state('aaa', {
    url: '/aaa',
    templateUrl: 'client/parties/views/aaa.ng.html',
    controller: 'Aaa'
  })

$urlRouterProvider.otherwise("/default");

And now, I want to search on my page, but the params MUST working with the URL. How to use params when I have $urlRouterProvider.otherwise? Actually, everything after /aaa/ in URL causes redirect to /default.

Important thing: I have more than 20 parameters, but when there're not selected, I don't want to pass it via URL. This is important because I think I can't do something like url: '/details/:param1:param2:param3:param4',

Can you help me?

Upvotes: 0

Views: 769

Answers (1)

nggonzalez
nggonzalez

Reputation: 160

Looking at the documentation for ui-router, it doesn't seem like it is possible to not have it redirect without having at least one parameter defined on the state's route.

To accomplish what you want, I think the best is to use a catch all parameter of some sort. It's either that, restricting deep-linking, or reducing the amount of parameters and manually defining it.

  1. Define a catch all parameter as shown below. In this case the parameter is path redirects will not take place if there is nothing after "/files/":

    '/files/{path:.*}' - Matches any URL starting with '/files/' and captures the rest of the path into the parameter 'path'.
    '/files/*path' - Ditto. Special syntax for catch all.

  2. Define one parameter on a new route, and then split the one parameter into multiple parameters in the controller.

Upvotes: 1

Related Questions