How to form the Query string in web address url in Angular state router by using state go method

后端 未结 1 659
囚心锁ツ
囚心锁ツ 2021-01-28 05:35

I have a product list page, there have list of products,when click the particular products, call the function and in the function state.go.

Not working in dynami

相关标签:
1条回答
  • 2021-01-28 06:21

    The way the parameters are defined in your url is incorrect. Anyway, one option is to use the lifecycle methods and return a target

    .state('home.product.detail', {
        url: '/products/?productID&?brand&?store',
        params:{
            'productID': {
                value: "redminote4", 
                squash: true
            }
            'brand': {
                value: "x", 
                squash: true
            }, 
            'store': {
                value: "amazon", 
                squash: true
            }
    },
    data: {
        displayName: '',
        displayImg: 'Images/productsHeaderIcon.png'
    },
    onEnter: ['$transition$', '$state$', 'LoginHome', function(transition, state, LoginHome){
    
        if(!transition.options().resolvedParams){
           return transition.router.stateService.target(
                     transition.to().name, 
                     {
                        productID: 'redminote4', 
                        brand: 'x', 
                        store:'amazon'
                     },
                     { 
                        resolvedParams: true 
                     }
               );
            }
        }]
    

    This interrupts the state change and replaces it with your new target which now is populated with your parameters and has a custom key in the options object that I'm using in this example to not redirect the state change again.

    You can learn more about the lifecycle here and the TargetState we return here

    0 讨论(0)
提交回复
热议问题