app state with optional param and no trailing slas

2019-06-21 04:35发布

.state('tabs.map', {
    url:'/map/{location_id}',
    params: {
      location_id: { value: -1 }
    },
    views: {
      'map-tab':{
        templateUrl:'templates/map.html',
        controller:'MapCtrl'
      }
    }
  })

I've tried a number of different options for optional params that I've found on the web but none of them work exactly like I'm looking for. The code I've added allows for:

  • /tab/map/.*?

  • /tab/map/

but not

  • /tab/map

I'm not sure why the trailing slash is causing a problem because from what I've read it shouldn't be a problem. Does anyone know how to resolve this?

Recently Consulted

Solution

Introduction of squash to param variable

.state('tabs.map', {
    url:'/map/:location_id',
    params: {
      location_id: { value:null, squash:true }
    },
    views: {
      'map-tab':{
        templateUrl:'templates/map.html',
        controller:'MapCtrl'
      }
    }
  })

1条回答
甜甜的少女心
2楼-- · 2019-06-21 05:05

You can use squash parameter to allow without trailing slash

  params: {
      location_id: {
        value: null,
        squash: true
      }
   }
查看更多
登录 后发表回答