角ui路由器后退按钮问题 [英] angular ui router back button issue

查看:91
本文介绍了角ui路由器后退按钮问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'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'
      });

  });

在这里,我的应用程序使用网址/college/search调用第一状态,即搜索".在控制器内部,我过渡到另一个状态searchCollegeFilter. 我想做的是,当用户单击浏览器的后退"按钮时,将用户导航回到他们的后退位置.假设他们来自"/",我希望他们返回首页.但是在浏览器的历史记录中,有2个条目用于大学/搜索.我只希望这是第一次.

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.

推荐答案

我在其他应用程序中所做的工作将达到目的:

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

基本上:指定父级状态

->然后,逻辑变得容易了.

-> Then the logic is becoming easy.

您不必详细说明历史记录或后退按钮.

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

基本:

->签入

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

->如果

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

这篇关于角ui路由器后退按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆