本文介绍了可以使用 Angular UI 路由器在 URL 中隐藏一些参数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过参数向新的 ui-view 传递两个值:

I want to pass two values to new ui-view via params:

  • 商品编号
  • 对象列表

但是,我希望新视图仅显示浏览器 URL 中的 id,而不是字符串化的对象数组:

However, I'd like the new view to show only the id in the browser URL and not the stringified array of objects:

http://www.myapp.com/#/my-view/4

INSTEAD OF

http://www.myapp.com/#/my-view/4?flskdjalfjaewoijoijasdlfkjösldakjföliwejöorijo

是否可以 a) 将隐藏的对象数组传递给 ui-view 或 b) 传递两者但将另一个从浏览器 URL 中隐藏?

Is it possible to either a) pass the array of objects hidden to the ui-view or b) pass both but hide the other from the browser URL?

我找到了有关壁球参数的一些信息,但无法让它执行我正在尝试的操作.

I found something about the squash parameter, but couldn't get it to do what I'm trying.

这是我的观点:

  $stateProvider
  .state('show', {
    url: "/show/{itemId}?{itemList}",
    views: {
      'mainView': {
        templateUrl: 'views/itemView.html',
        controller: 'showController',
        params: {
          itemList: {
            value: null,
            squash: true
          },

          itemId: -1
        }
      }
    }

如何在不隐藏 id 的情况下隐藏 URL 中的对象列表?

How can I hide the list of objects from the URL, without hiding the id?

推荐答案

您走在正确的道路上.要隐藏参数,您必须像您一样在 params 中定义它们,而不是 squash.

You are on the right path. To hide params you have to define them in params as you do, without squash.

您的示例应如下所示:

  $stateProvider
  .state('show', {
    url: "/show?itemId",
    views: {
      'mainView': {
        templateUrl: 'views/itemView.html',
        controller: 'showController'
        // params do not work here! They need to be attached below ...
        // $stateProvider.state('show', {url:'/show/:url_param',views:{}, params: {}})
      }
    },
    resolve: {},
    params: {
      itemList: {
        value: null
      }
    }
  })

参见示例:http://plnkr.co/edit/wEjwCVWMKTyuSdyLr0og?p=preview

这篇关于可以使用 Angular UI 路由器在 URL 中隐藏一些参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 00:22
查看更多