- Add an instance of “\Magento\Framework\UrlInterface” in your calss and use that:
protected $urlBuider;
public function __construct(
....
\Magento\Framework\UrlInterface $urlBuilder,
....
) {
....
$this->urlBuilder = $urlBuilder;
....
}
Then you can use this:
$url = $this->urlBuilder->getUrl('url/path/here', $paramsHere = array());
It works for me !!!