Magento 2.x – how to force redirect to controller on observer


In this tutorial i am going to show you how to redirect a user to any particular controller. This was made on an observer, but could be potentially used in any scenario.

This was developed taking as reference how the \Magento\Customer\Model\Session::authenticate() method works.

Observer:


After that, remember to proceed with recompiling, as follows:


 

And that’s it. Happy coding!

Be safe. #StayAtHome #QuedateEnCasa.