I have deep links to nested views, for e.g.: #/news/12. When I type this url into URL bar in browser then app redirects me to the correct view but I don’t see back button.
I would like go back to the news view.
Is it possible to add view (news) to the $ionicHistory?
OK, but I need redirect users from one tab to another. For example. I am on events tab and I would like to go to the news tab and open news with ID=5. How to display back button to news overview on that page?
So if we put all of this together, we can create a function to redirect us, as seen in the codepen.
Then if we need to, we can use an ion-nav-button in place of a back-button.
I am (mis)-using ionic for Web apps, too, and face the same problem. I was thinking about implementing some “ion-nav-back-button-default” attribute directive, so you can specify a default click action or routing href if there is no “back” view in the history stack. I’m wondering if this is something that would be generally useful, and could be added to the back button in ionic proper…
I digged out this topic because I’m struggling with the same problem. My solution is to test for the initial state change and then navigate the complete view stack to the deep link view:
Angular.module(App)
.run([
'$rootScope', '$state', '$timeout',
function($rootScope, $state, $timeout) {
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams, options) {
if (fromState.name === '') {
// drop your deep linkable states here
switch (toState.name) {
case 'company':
event.preventDefault();
// Navigate to the first level
$state.go('companies');
$timeout(function() {
// navigate to the second level
$state.go(toState.name, toParams);
}, 0);
break;
}
}
});
}
]);