Magento 2.4 – CMS No Route Page Not Working

404-pagemagento2.4

A page with an invalid url should redirect to a page not found, but it throws an error

TypeError: Magento\Framework\App\FrontController::processRequest(): Argument #2 ($actionInstance) must be of type Magento\Framework\App\ActionInterface, Magento\Framework\Controller\Result\Redirect\Interceptor given, called in vendor\magento\framework\App\FrontController.php on line 147 and defined in vendor\magento\framework\App\FrontController.php:177

enter image description here

Can anyone help?
Thanks

Best Answer

Check any third-party modules that may influence router selection (using plugins or own router), which may result in an error. Try disabling all suspicious modules and check the result (don't forget to run setup:di:compile first).

Analyze the di.xml files within these modules for any entries associated with the routerList argument. This will provide insight into the sequence and any custom routers that might be active.

Check routers list (and it's order) in the Magento\Framework\App\FrontController::dispatch() method (using xDebug or other debug method):

Inside the dispatch() method, you will find a loop that goes through all the routers and tries to match the request to a specific router. This loop is where Magento tries each router in sequence until it finds one that can handle the request:

foreach ($this->_routerList as $router) {
    $actionInstance = $router->match($request); // Main debugging point!
    if ($actionInstance) {
        $request->setDispatched(true);
        $this->response->setNoCacheHeaders();
        if ($actionInstance instanceof \Magento\Framework\App\Action\AbstractAction) {
            $result = $actionInstance->dispatch($request);
        } else {
            $result = $actionInstance->execute();
        }
        // ...
    }
}

Seems like some custom router returns incorrect instance.