How to pass parameters using ui-sref in ui-router to controller

前端 未结 3 1462
滥情空心
滥情空心 2020-11-22 08:48

I need to pass and recieve two parameters to the state I want to transit to using ui-sref of ui-router.

Something like using the link below for transiti

3条回答
  •  无人共我
    2020-11-22 09:38

    You don't necessarily need to have the parameters inside the URL.

    For instance, with:

    $stateProvider
    .state('home', {
      url: '/',
      views: {
        '': {
          templateUrl: 'home.html',
          controller: 'MainRootCtrl'
    
        },
      },
      params: {
        foo: null,
        bar: null
      }
    })
    

    You will be able to send parameters to the state, using either:

    $state.go('home', {foo: true, bar: 1});
    // or
    Go!
    

    Of course, if you reload the page once on the home state, you will loose the state parameters, as they are not stored anywhere.

    A full description of this behavior is documented here, under the params row in the state(name, stateConfig) section.

提交回复
热议问题