Skip to content

Magento 2: How to use redirect in Router.php

I am trying to redirect a cms page to a custom controller.
in router.php
I can check the current URL, If the current URL is as an example if it matches /test-url i want to do a redirect to /test-url-router

    if ($identifier == 'test-url') {
       $this->_response->setRedirect('test-url-router');
       $request->setDispatched(true);
       return $this->actionFactory->create(MagentoFrameworkAppActionRedirect::class);
    }

This works it does redirect me to test-url-router (the page will be 404)
I want to show my custom controller which I am not sure of how to get this working.

$request->setModuleName('custom') //module name
        ->setControllerName('custom') //controller name
        ->setActionName('index'); //action name;

is it possible to get this both working?