在本篇博客中,我将演示如何管理客户帐户仪表板页面的导航链接。

 

步骤1

首先,您需要在主题中创建customer_account.xml:

app/design/frontend/_YOUR_VENDOR_/_YOUR_THEME_/Magento_Customer/layout/customer_account.xml

 

添加自定义链接

我们需要做的就是将以下代码添加到我们的布局文件中:

<referenceBlock name="customer_account_navigation">
    <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-custom-link" after="-" >
         <arguments>
             <argument name="label" xsi:type="string" translate="true">Custom Link Label</argument>
             <argument name="path" xsi:type="string">custom-path</argument>
         </arguments>
    </block>
</referenceBlock>

 

重设链接

<move element="LINK_YOU_WANT_TO_MOVE" destination="customer_account_navigation" AFTER_OR_BEFORE="NEW_POSITION" />
 
<!-- eg. "My Wish List" move after "My Orders" -->
<move element="customer-account-navigation-wish-list-link" destination="customer_account_navigation" after="customer-account-navigation-orders-link" />

我们将元素从它原来的位置“移动”并放回那里,同时告诉Magento 2将它放置在我们想要的链接之后/之前。

 

删除链接

为了简化内容,在下面的示例中,我将向您展示如何逐个删除导航中的链接。

<!-- Store credit -->
<referenceBlock name="customer-account-navigation-customer-balance-link" remove="true"/>
 
<!-- Downloadable product link -->
<referenceBlock name="customer-account-navigation-downloadable-products-link" remove="true"/>
 
<!-- Subscription link -->
<referenceBlock name="customer-account-navigation-newsletter-subscriptions-link" remove="true"/>
 
<!-- Billing agreement link -->
<referenceBlock name="customer-account-navigation-billing-agreements-link" remove="true"/>
 
<!-- Product review link -->
<referenceBlock name="customer-account-navigation-product-reviews-link" remove="true"/>
 
<!-- My credit card link -->
<referenceBlock name="customer-account-navigation-my-credit-cards-link" remove="true"/>
 
<!-- Account link -->
<referenceBlock name="customer-account-navigation-account-link" remove="true"/>
 
<!-- Account edit link -->
<referenceBlock name="customer-account-navigation-account-edit-link" remove="true"/>
 
<!-- Address link -->
<referenceBlock name="customer-account-navigation-address-link" remove="true"/>
 
<!-- Orders link -->
<referenceBlock name="customer-account-navigation-orders-link" remove="true"/>
 
<!-- Wish list link -->
<referenceBlock name="customer-account-navigation-wish-list-link" remove="true"/>
 
<!-- Gift card link -->
<referenceBlock name="customer-account-navigation-gift-card-link" remove="true"/>
 
<!-- Gift registry -->
<referenceBlock name="customer-account-navigation-giftregistry-link" remove="true"/>
 
<!-- Reward points -->
<referenceBlock name="customer-account-navigation-reward-link" remove="true"/>
 
<!-- Order by SKU -->
<referenceBlock name="customer-account-navigation-checkout-sku-link" remove="true"/>