0
'use strict'; angular.module('cbApp') .config(function ($stateProvider) { $stateProvider .state('search', { url: '/college/search', templateUrl: 'app/collegesearch/views/collegesearch.html', controller: 'collegeSearchCtrl' }) .state('searchCollegeFilter', { url: '/college/search/:streamId?cities&courses&branches&ordering', templateUrl: 'app/collegesearch/views/collegesearch.html', controller: 'collegeSearchCtrl' }); }); 

Here my application calls the 1st state i.e 'search' with a url /college/search. Inside the controller I transition to another state searchCollegeFilter. What I wanna do is navigate the user back to the back they came from when they click the browser back button. Say they came from '/' I want them to go back to home page. But in browser back history there are 2 entries for college/search. I want this to happen only for the 1st time.

1

2 Answers 2

1

For this northing is do with angularjs, the thing is you need to watch browser back event before navigating "window.onhashchange". By observing that you can make you check and can redirect default page

Sign up to request clarification or add additional context in comments.

Comments

1

What I am doing in a different application would serve the purpose:

Basically: Specify parent states!

-> Then the logic is becoming easy.

You don't have to be specific about history or back button or anything like that.

Basically:

-> Check in

  • $rootScope.$on("$onstateChange", ...

-> If

  • the fromState.parent equals toState.parent
  • then $window.history.replaceState({}, "My Detail State Page", $state.url(toState)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.