We can use below syntax to get current Url:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
protected $_urlinterface; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\UrlInterface $urlinterface, array $data = [] ) { parent::__construct($context, $data); $this->_urlinterface = $urlinterface; } public function getCurrentUrl() { return $this->_urlinterface->getCurrentUrl(); // Give the current url of recently viewed page } |