0

I have a ui router route that is defined as follows

        $stateProvider
        .state('search', {
            url: '/search',
            abstract: true,
            parent: 'loggedIn',
            views: {

                wrapper: {
                    controller: 'MyCtrl',
                    controllerAs: 'myCtrl',
                    templateUrl: '/scripts/views/search/views/search.wrapper.html'
                }
            }
        })
        .state('search.subs', {
            url: '',
            resolve: {
                isLoggedIn: isLoggedIn
            },
            views: {
                body: {
                    controller: 'SearchBodyCtrl',
                    controllerAs: 'searchBodyCtrl',
                    templateUrl: '/scripts/views/search/views/search.body.html'
                }
            }
        });

Anyways the issue is that I cannot generate a query parameters so that the url looks like /search?hello=world I tried using $state.transitionTo('search.subs', {hello: 'world'}) but that didn't work. I figured any params I passed that did not match would just be put in the query string but that is not the case.

1 Answer 1

2

This should do what you want to do:

    .state('search.subs', {
        url: '?hello', // This appends to the parent url
          ....

Afterwards you can just use $state.go('search.subs', { hello : 'world' }) to transition to the search.subs state.

https://github.com/angular-ui/ui-router/wiki/URL-Routing#query-parameters

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

1 Comment

Yeah, I was really hoping for a dynamic API, turns out there isn't one. :(

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.