I'm new to Magento. In my Magento 2.3.3 project, when adding a new link to my account navigation and I want to show the content in the right-side container block. Unfortunately, when I press on it, it goes to a new window that says the page doesn't exist. My code below:
In app/code/PCE/NewPassword/web/frontend/layout/customer_account.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\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-newpassword-change-link">
<arguments>
<argument name="path" xsi:type="string">newpassword/change</argument>
<argument name="label" xsi:type="string">New Password</argument>
<argument name="sortOrder" xsi:type="number">250</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
In app/code/PCE/NewPassword/web/frontend/layout/routes.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route frontName="newpassword" id="newpassword">
<module name="PCE_NewPassword"/>
</route>
</router>
</config>
In app/code/PCE/NewPassword/web/frontend/layout/newpassword_change_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="customer_account"/>
<head>
<title>
Your First Link
</title>
</head>
<body>
<referenceContainer name="content">
<block class="PCE\NewPassword\Block\ResetPassword" name="newpassword.change.index" template="PCE_NewPassword::change/index.phtml" cacheable="false" />
</referenceContainer>
</body>
</page>
In app/code/PCE/NewPassword/Controller/Change/Index.php
<?php
namespace PCE\NewPassword\Controller\Change;
class Index extends \Magento\Framework\App\Action\Action
{
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory resultPageFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
)
{
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
/**
* Default customer account page
*
* @return void
*/
public function execute()
{
return $this->resultPageFactory->create();
}
}
?>
In app/code/PCE/NewPassword/Block/ResetPassword.php
<?php
namespace PCE\NewPassword\Block;
class ResetPassword extends \Magento\Framework\View\Element\Template
{
public function __construct(
\Magento\Backend\Block\Template\Context $context,
array $data = []
)
{
parent::__construct($context, $data);
}
public function getHelloWorld()
{
return 'Hello World';
}
}
?>
In app/code/PCE/NewPassword/web/frontend/index.phtml
<h2>
<?php echo $block->getHelloWorld(); ?>
</h2>
<?php
echo 'My First Link Page';
?>
Where I make the mistake and how can I resolve the issue? Thanks in advance.