Reputation: 16399
I have a URL parameter that I want to exist in all states. The parameter is 'asUser' and it allows admins to look at the app as another user. I tried:
$stateProvider
.state("root", {
params: ['asUser']
})
.state("root.login", {
url: "/login",
templateUrl: "/static/partials/login.html",
controller: 'LoginCtrl'
})
...
But when I go to a url /login?asUser=123
, I get this error in the console:
Failed to instantiate module myApp due to:
Missing required parameter 'asUser' in state 'root.login'
Is there anyway to have a global parameter like this with ui.router, without having to mention it in every state and pass it around everywhere?
Upvotes: 2
Views: 3196
Reputation: 5770
I would do:
.state("root", {
url: '/?asUser'
})
You'll still have to handle parameter inheritance on your own, but that should at least make it that parameter valid across all states.
Upvotes: 2