How to redirect to state if specific stateParam is empty

前端 未结 2 1037
悲哀的现实
悲哀的现实 2021-02-01 03:48

I\'m not sure if the way I am doing it is correct, any advice would be appreciated.

I have a Restaurant Selector, which the user can select a restaurant from. Then all o

2条回答
  •  情话喂你
    2021-02-01 04:23

    I needed to get this working, so to add details to the answer from @NicolasMoise:

    .state('restaurant', {
        url: '/restaurant/:restaurantId',
        template: "",
        onEnter: function ($state, $stateParams, $cookies) {
          console.log($stateParams.restaurantId);
          if (!$stateParams.restaurantId) {
            $stateParams.restaurantId = $cookies.restaurantId;
            $state.go('restaurant.restaurantID');
          }
        },
    })
    

    I didn't test the cookies portion of this, but the conditional and state change worked.

提交回复
热议问题