I want to add custom link in customer's navigation.I have developed below code but getting 404 - not found issue while click on the tab.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_account_navigation">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="module">
<arguments>
<argument name="path" xsi:type="string">module/customer/list</argument>
<argument name="label" xsi:type="string" translate="true">My Data</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Then I create a controller file name : List.php at modulename/controller/customer
<?php
namespace namespace\modulename\Controller\Customer;
use Magento\Sales\Controller\OrderInterface;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
class List extends \Magento\Framework\App\Action\Action
{
/**
* @var PageFactory
*/
protected $resultPageFactory;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
/**
* Customer order history
*
* @return \Magento\Framework\View\Result\Page
*/
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->set(__('My Data'));
$block = $resultPage->getLayout()->getBlock('customer.account.link.back');
if ($block) {
$block->setRefererUrl($this->_redirect->getRefererUrl());
}
return $resultPage;
}
}
Block file at namespace/module/block/customer/test/list.php
<?php
namespace namespace\modulename\Controller\Customer;
use Magento\Sales\Controller\OrderInterface;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
class List extends \Magento\Framework\App\Action\Action
{
/**
* @var PageFactory
*/
protected $resultPageFactory;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
/**
* Customer order history
*
* @return \Magento\Framework\View\Result\Page
*/
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->set(__('My Orders'));
$block = $resultPage->getLayout()->getBlock('customer.account.link.back');
if ($block) {
$block->setRefererUrl($this->_redirect->getRefererUrl());
}
return $resultPage;
}
}
and add xml file : modulename_test_list.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_account_navigation">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="modulename">
<arguments>
<argument name="path" xsi:type="string">modulename/customer/list</argument>
<argument name="label" xsi:type="string" translate="true">My Data</argument>
</arguments>
</block>
</referenceBlock>
</body>