Angular definition of dynamic user definition ui-router

We have a search page, and we have thousands of search attributes that can be defined using the admin panel. A typical search results page has this URL:

http://example.com/search?a12=3213&a314=412412&a247=1941829&.... 

When we want to implement this page as a SPA with AngularJS using angular-ui-router , I could not understand how we can determine the route configuration and how we can read all the search parameters from querystring. Because ui-router forces you to define each queryparam parameter in the route configuration for use in $stateParams .

 $stateProvider.state('search', { url: '/search?a1&a2&a3&a4&a5' // what about a1314? controller: function ($stateParams) { console.log($stateParams.a1314); } }); 

Do you know a workaround?

+6
source share
1 answer

you can use $ location.search () in the url: '/search' controller search controller

it returns the search part (as an object) of the current url when called without any parameter.

 var searchObject = $location.search(); // => {a12: '3213', a314: '412412'} console.log(searchObject .a12); //3213 

and for the route you can use

  url: '/search*' 

to match

+2
source

Source: https://habr.com/ru/post/980275/


All Articles