Angular ui route stateparam in substate

2019-09-07 06:52发布

问题:

I have some issues with using a stateparam in a substate.

This is my 'master' state

.state("shop", {
    abstract: true,
    url: '/shop/:nameSlug',
    templateUrl: '/views/shop/index.html',
    controller: 'shopController',
    params: {
        nameSlug: null,
        }
    })

And this is my substate:

.state('shop.payment-success', {
    url: '/payment-success?transactionid',
    templateUrl: '/views/payment-success.html',
    controller: 'checkoutController'
})

I want to use the param 'transactionid' in my controller, but when I log it, it's undefined.

I have tried with $stateParams and $state.params, but there is no difference between them.

Is there a way to make transactionid available in 'checkoutController'?

For your information: the param ?transactionId is coming from a payment gateway and I can't change it. It contains the orderId, what I have been needed for a check for a genuine payment.

回答1:

try this: ui-router documentation

.state('shop.payment-success', {
    url: '/payment-success',
    params: {
          transactionid: null
    }  
    templateUrl: '/views/payment-success.html',
    controller: 'checkoutController'
})