I am wondering how can I go to the same state, with different $stateParam
?
I was trying to go with:
$state.go('^.currentState({param: 0})')
However, it was not working.
You might want to use this piece of code:
<a ui-sref=".({param: 0})"></a>
No need to use controller.
the params are second paramater of the go()
method
$state.go('^.currentState', {param: 0})
Convenience method for transitioning to a new state. $state.go calls $state.transitionTo internally but automatically sets options to { location: true, inherit: true, relative: $state.$current, notify: true }. This allows you to easily use an absolute or relative to path and specify only the parameters you'd like to update (while letting unspecified parameters inherit from the currently active ancestor states).
In my case, I wanted to reload the same state, but with different parameters. (null
in this specific occurrence)
The situation is as follows: We have a website with different companies, each with their own branding page. You can visit other companies' pages and there's a menu entry to quickly visit your own.
A company's page is located under /company/somecompanyid
, whereas your own page will be loaded when visiting /company
. Without the addition of an id. Or company_id: null
in code.
The problem
When you're viewing a random company's page, let's say company/123456
and you click the designated menu entry to visit your own page, nothing would happen!
Ui-router believes you're on the same route and simply keeps you there.
The solution
Add the following to your template:<a ui-sref="company" ui-sref-opts="{reload: true, inherit: false}" ... ></a>
What does it do?reload: true
This will force your state to reload. But it'll copy your current route parameters. Which means your still seeing the other company's page.
inherit: false
Setting the inherit
property to false
will force ui-router to use the params you provided. In my case, the companyId was null
and user's personal page was loaded. Hurray!
You can find all ui-sref-options on the documentation pages. ui-sref-options
If you'd like to reload your state, you can also use ui-sref-opts. Passing in the reload: true
option, will reload the current state.
<a ui-sref-opts="{reload:true}" ui-sref="app.post.applicants">Applicants</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With