I am trying to use this code to redirect to a frontend URL, but it always redirects to the admin dashboard. I searched for and tried a lot of demo code, but I can't get it to work. I assume all attributes were set correctly.
$url= $this->_storeManager->getStore(1)->getUrl('storelocator/index/index');
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setUrl($url);
return $resultRedirect;
From here:
public function __construct(
...
\Magento\Store\Model\StoreManagerInterface $manStore,
...
) {
...
$this->manStore = $manStore;
...
}
public function execute()
{
...
$resultRedirect = $this->resultRedirectFactory->create();
$route = 'customer/account'; // w/o leading '/'
$store = $this->manStore->getStore();
$url = $store->getUrl($route, [$parm => $value]); // second arg can be omitted
$resultRedirect->setUrl($url);
return $resultRedirect;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With