Prepend optional attribute in angular ui-router URL

后端 未结 3 1190
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 02:12

Is there a way to have an optional attribute at the beginning of the url in ui-router? If so, how?

I want to achieve sth like this:

.state(\'events\'         


        
3条回答
  •  离开以前
    2020-12-04 02:51

    I see no reason why you wan't do it in a standard ui-router state setup.

    DEMO

    JAVASCRIPT

    angular.module('app', ['ui.router'])
    
      .config(function($stateProvider, $urlRouterProvider) {
    
        $stateProvider
    
          .state('state1', {
            url: ':city/events/:id',
            templateUrl: 'partials/events.html',
            controller: 'EventsController'
          })
    
          .state('state2', {
            url: ':abc/cities/:x/:y',
            templateUrl: 'partials/cities.html',
            controller: 'CitiesController'
          });
    
      })
    
      .controller('EventsController', function($scope, $stateParams) {
    
        angular.extend($scope, $stateParams);
    
      })
    
      .controller('CitiesController', function($scope, $stateParams) {
    
        angular.extend($scope, $stateParams);
    
      });
    

提交回复
热议问题