如何在状态URL中嵌套多个ID?

时间:2015-05-07 23:20:05

标签: regex angularjs angular-ui-router

我正试图建立一个我可以冷却导航并且不会丢失面包屑路径结构的状态。理想情况下,网址看起来像这样:

site.com/stuff/id1/id2/id3/id4/id5

其中ids 1-5最终处于一个stateParam。

我必须支持潜在的无限深度。尝试与{path:。*}匹配的正则表达式失败。当我尝试浏览时,我得到一个看似已经消毒的网址(84070/84057/84604变为84070%252F84057%252F84604)。

可以找到最小的示例插件here。请务必查看整个屏幕,了解网址是如何被破坏的。

pnlkr代码:

    angular.module('inifinteRoutePrototype', ['ui.router'])
  .config(function($stateProvider){
    $stateProvider
      .state('stuff', {
        url: '/stuff/{path: *.}',
        templateUrl: 'ids.html',
        controller: 'idsCtrl'
      });
  })
  .run(function($state){
    $state.go('stuff'); //Default to the zipcode form state
  })


  // The controller for the zipcode form
  .controller('idsCtrl', function($scope, $state, $stateParams){

    function cleanupUrl(){
      return $stateParams.path.split('/');
    }

    $scope.ids='84070/84057/84604';
    var id = '80000';
    console.log($stateParams.path);

    $scope.go = function(){
      console.log('Attempting navigtation: ' + $state.href('stuff', {path: $scope.ids}));
      $state.go('stuff', {path: $scope.ids});
    };

    $scope.path = cleanupUrl();
    $scope.id = $stateParams.id;


  });

0 个答案:

没有答案