Shopware 店面插件中的 Window Router 错误

问题描述 投票:0回答:1

我收到错误

未捕获(承诺中)类型错误:无法在 XMLHttpRequest.open 处读取未定义的属性(读取“切片”)

当我尝试使用该功能时

window.router['frontend.api.name']

window.router
函数应该返回
url path
,但在这里它会产生错误。我该如何解决?

this._client.post(window.router['frontend.api.name'], payload, this._setContent.bind(this));
shopware shopware6
1个回答
0
投票

您必须先注册该路线。看看商店里的商品

vendor/shopware/storefront/Resources/views/storefront/layout/meta.html.twig

{% block layout_head_javascript_router %}
{# Register all routes that will be needed in JavaScript to the window.router object #}
<script>
    window.activeNavigationId = '{{ page.header.navigation.active.id }}';
    window.router = {
    'frontend.cart.offcanvas': '{{ path('frontend.cart.offcanvas') }}',
    'frontend.cookie.offcanvas': '{{ path('frontend.cookie.offcanvas') }}',
    'frontend.checkout.finish.page': '{{ path('frontend.checkout.finish.page') }}',
    'frontend.checkout.info': '{{ path('frontend.checkout.info') }}',
    'frontend.menu.offcanvas': '{{ path('frontend.menu.offcanvas') }}',
    'frontend.cms.page': '{{ path('frontend.cms.page') }}',
    'frontend.cms.navigation.page': '{{ path('frontend.cms.navigation.page') }}',
    'frontend.account.addressbook': '{{ path('frontend.account.addressbook') }}',
    'frontend.country.country-data': '{{ path('frontend.country.country.data') }}',
    'frontend.app-system.generate-token': '{{ path('frontend.app-system.generate-token', { name: 'Placeholder' }) }}',
};
    window.salesChannelId = '{{ app.request.attributes.get('sw-sales-channel-id') }}';
</script>
{% endblock %}

扩展该块并将您的路线添加到该 js 对象,就像 Shopware 那样

© www.soinside.com 2019 - 2024. All rights reserved.