6

We have a search page and we have thousands of search attributes that can define by an admin panel. A characteristic search result page has a url like that:

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

When we want to implement that page as a SPA with AngularJS by using angular-ui-router, I couldn't understand, how can we define that route configuration and how can we read all search parameters from querystring. Because ui-router forces to define every queryparam possibilities on route configuration to use them 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?

1

1 Answer 1

2

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

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

var searchObject = $location.search();

// => {a12: '3213', a314: '412412'}

console.log(searchObject .a12); //3213

and for route you can use

 url: '/search*' 

so it will match

Sign up to request clarification or add additional context in comments.

2 Comments

The main problem is, if a url comes with a query param that not defined in route config, ui-router removes it from url and shows page without it.
How will I generate a link to that url?

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.