Cannot get back to parent view when navigating to

2019-07-13 20:56发布

问题:

I have an application that uses Ionic tabs; a simple example of my problem can be reproduced there.

There are two tabs: home and settings.

In the state manager, there is a single top-level (abstract) state tabs. The nested tabs.home state describes the home tab. The nested tabs.settings state is abstract and contains two nested states: tabs.settings.index and tabs.settings.sub. The former describes the settings tab, and the latter shows a sub-view of my settings tab (a very simple example of this setup can be found on the UI router wiki).

The home tab offers a button to navigate to the tabs.settings.sub state directly (it uses $state.go(), but the behavior is the same when using ui-sref).

The problem is that after navigating to this tabs.settings.sub state, my tabs.settings.index state is inaccessible from now on: clicking the settings tab always uses the tabs.settings.sub state.

I can think of two approaches to get back to the parent view (ie. tabs.settings.index state), but I don't know how to implement them, and as a consequence don't whether it's feasible:

  1. Have a back button to get back to the calling view (tabs.home state); or
  2. When clicking on the settings tab, bring to the parent view if it were to show the sub one

How can I get back to my tabs.settings.index state? Thanks,

回答1:

I worked around this problem by showing the view of state tabs.settings.sub in a modal. More details in this answer.