I'm trying to build a Magento 2 module that has an admin section.
But apparently I'm doing something wrong and when I click the admin menu link, I get redirected to the dashboard.
I've seen this question: Magento2 custom admin menu link is redirecting back to admin dashboard but that does not help much.
There is nothing in the logs, but for the moment, I don't care what the problem is.
What I need is a way to debug this.
Where is the actual redirect happening so I know where to start?
Magento 2 – Redirected to Dashboard When Something is Wrong
errormagento2redirect
Best Answer
In app/bootstrap.php enable 'display_errors'
enable developer mode.
Disable cache and check admin routes.xml file of your module frontname.
EDIT
It is redirect from Magento\Backend\App\AbstractAction
In _processUrlKeys function redirecting from $this->_redirect($this->_backendUrl->getStartupPageUrl());
Above is possible area to check. Maybe it is helpful.
[EDIT BY OP]
The method
_processUrlKeys
in the code above is the one that does the redirect.And here is why.
the backend router, when it does not find a controller action to map the url on, it maps it to the 404 page (
Magento\Backend\Controller\Adminhtml\Noroute\Index
class).then comes the
_processUrlKeys
method that checks the url key.And this url key depends on the controller name. Since the key is generated based on the url
module/controller/action
it will not match against the key for thenoroute
action and$_isValidSecretKey
will befalse
hence the redirect.The redirect does not happen if the
Add Secret Key to URLs
is off in the config panel. In this case you get a simple 404 page.