简体   繁体   English

角ui路由器后退按钮问题

[英]angular ui router back button issue

'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 ie 'search' with a url /college/search. 在这里,我的应用程序使用网址/ college / search调用第一状态,即“搜索”。 Inside the controller I transition to another state searchCollegeFilter. 在控制器内部,我转换到另一个状态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. 但是在浏览器的历史记录中,有2个条目用于大学/搜索。 I want this to happen only for the 1st time. 我希望这仅是第一次发生。

For this northing is do with angularjs, the thing is you need to watch browser back event before navigating "window.onhashchange". 因为这个问题与angularjs有关,所以事情是您需要在浏览“ window.onhashchange”之前观看浏览器的后退事件。 By observing that you can make you check and can redirect default page 通过观察可以检查并可以重定向默认页面

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", ... $ rootScope。$ on(“ $ onstateChange”,...

-> If ->如果

  • the fromState.parent equals toState.parent fromState.parent等于State.parent
  • then $window.history.replaceState({}, "My Detail State Page", $state.url(toState) 然后$ window.history.replaceState({},“我的详细信息状态页”,$ state.url(toState)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM