Magento

How to Get Current URL in Magento 2?

Pinterest LinkedIn Tumblr
$urlInterface = \Magento\Framework\App\ObjectManager::getInstance()
    ->get(\Magento\Framework\UrlInterface::class);
$currentUrl = $urlInterface->getCurrentUrl();

Example:

private $urlInterface;

public function __construct(
...
\Magento\Framework\UrlInterface $urlInterface
...
) {
$this->urlInterface = $urlInterface;
}

public function getCurrentUrl()
{
    return $this->urlInterface->getCurrentUrl();
}

Write A Comment

Faster PHP Cloud Hosting