获取路径 Shopware 6 的参数

Get params of route Shopware 6

我尝试扩展产品详细信息页面并从路由中获取 productId


Shopware.Module.register('sw-product-content-element', {
  routeMiddleware(next, currentRoute) {
    if (currentRoute.name === 'sw.product.detail') {
          currentRoute.children.push({
              name: 'sw.product.detail.content-element',
              path: '/sw/product/detail/:id/content-element',
              component: 'sw-product-detail-content-element',
              meta: {
                  parentPath: "sw.product.index"
              },
              props: {
                default(route) {
                  console.log(route)
                  return {
                      productId: route.params.id
                  };
                }
              }
          });
      }
      next(currentRoute);
  }
});

我尝试将我的 productId 作为道具传递给我的组件,但在我的组件中 productIdundefined.

Component.register('sw-product-detail-content-element', {
  template,

  props: {
    productId: {
        required: true,
        type: String
    },
  },

  data() {
    return {
      product: null
    };
  },

  created() {
    console.log(this.productId)
  },
....

我找到了解决办法。我不需要将我的价值作为道具传递,我可以使用 this.$route.params.id

Component.register('sw-product-detail-content-element', {
  template,

  props: {
    productId: {
        required: true,
        type: String
    },
  },

  data() {
    return {
      product: null
    };
  },

  created() {
    this.productId = this.$route.params.id
    console.log(this.productId)
  },
....