feat: noHistory Feature
Type: feat
Platform: all
There are quite a few issues related to overcoming the back view in some apps. Most of the have been closed. I'll try to make a use case as clear as possible.
Scenario 1:
- App opens
- User tries to view something
- They aren't authorized
- Transition to a Login state
- User logs in
- Transition to originally requested state
- User Happy
- User goes back
- User sees login again
Scenario 2;
- Registered and logged in user opens app
- Goes to "Contacts" page
- Realized his BFF is missing from the list
- Taps "+"
- Transitions to and Add Contact page
- Enters the person's name and number
- Next Button takes to an Addresses page
- Enters the contacts address info.
- Saves new contact
- Goes "back"
- Is unfortunately seeing the add contact pages again
Scenario # 2 is especially contrived - but it happens. Now, you may be thinking, just do the forms in a modal! Good idea. But in some cases, designers/UX/client doesn't want a modal.
Feature Request:
In the router, be able to add a property like avoidHistory or noHistory. This would indicate that the view in question should never be added to the history stack. This way, after login in, the user will simply go back to the home page.
Right now, people are trying all kinds of ways to prevent the previous view being in their history stack. This feature would solve many of those problems.
FYI : Tried adding this to Trello but doesn't seem possible.
+1
This is the problem I am facing and was trying to solve without any success. Good that someone else took care to log a request.
Thanks for your time.
+1 Thanks for any help
$ionicHistory.nextViewOptions({historyRoot: true});
$state.go('app.home');
should solve your issue.
@calendee does @AlexYankee's approach work?
I did this in the landing page (welcome page):
$ionicHistory.clearHistory(); $ionicHistory.clearCache();
In the origin page (login page):
$ionicHistory.clearHistory(); $ionicHistory.nextViewOptions({ disableBack: true , historyRoot: true }); $ionicLoading.hide(); $scope.data.password = null; $state.go('welcome');
Regards!
On Mon, Mar 30, 2015 at 8:11 PM, Perry Govier [email protected] wrote:
@calendee https://github.com/calendee does @AlexYankee https://github.com/AlexYankee's approach work?
Reply to this email directly or view it on GitHub https://github.com/driftyco/ionic/issues/3418#issuecomment-87872778.
Christian Ochsenius
Director
M: (+56 9) 9489 6625
www.cursor.cl
T: (+56 2) 2656 4044
Los Leones 382 Of. 101, Providencia
ISO 9001:2008 CERTIFIED
@perrygovier No, that actually clears the entire history. So, in scenario # 2, if the user is down about 5 levels in the app (stupid I know) and then tries to add a new contact, when they do they can't get back to home anymore because the contact's list has suddenly become the history root.
+1
In my app, when a user create a new item, he is send in the item page, but if use the back button he is send on the create page, but I want to send him on the list page.
In fact, i think some functions are missing in $ionicHistory like :
remove(position); // Remove a specific entry in the history stack addAfter(position, page); // Add a stat in the history at the specified position
In other world, it would be nice if we can manage the history, so we can achieve what we want.
+1
I've solved this in the interim using the following decorator:
.config(function ($provide, $injector) {
var ionicHistory = $injector.get('$ionicHistoryProvider').$get();
var regFunc = ionicHistory.register.bind(ionicHistory);
ionicHistory.register = function (parentScope, viewLocals) {
if (viewLocals.$$state.noHistory) {
return {};
}
return regFunc(parentScope, viewLocals);
};
$provide.decorator('$ionicHistory', function () {
return ionicHistory;
});
})
Am I doing anything incredibly stupid here?
UPDATE: It doesn't work!
Hi, I have a simple login based application in which user can access About menu with or without login, issue came with android hardware back button,
Login screen > About page > From Menu go to Login > Press hardware back button > Application Should get closed rather go to About page.
Below is the code for navigation to login screen.
$scope.login = function() {
$ionicHistory.nextViewOptions({
disableBack: true,
disableAnimate: true,
historyRoot: true
});
$ionicHistory.clearCache();
$ionicHistory.clearHistory();
$ionicSideMenuDelegate.toggleLeft();
$state.go('login');
};
I am using ionic rc release 4 currently.
In the mean time, here's something that worked for me:
$state.go(stateName, null, { location: 'replace' });
This will update the current history entry to the new state you're navigating to, and won't create a new history entry for the previous state.
See the ui-router docs here for details: http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state
+1
+1, I came across scenario 1 in my app. I too have been trying the clear cache, clear history, disable back and history root stuff. Leads to subtle bugs 2-3 views down in the stack. It would be nice to have a noHistory feature.
Will try @lewisl9029's suggestion, seems clean and interesting.
Hello all! Since we are not planning on adding any additional features to Ionic 1 I am going to go ahead and close this issue for now. Thanks!
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.