Magento – redirect to a controller from block magento2

magento-2.1magento2

I was trying to check few things on a function defined on the block.So if that condition doesn't match, I need to redirect from that function defined on that block to the controller action.

Can anyone please suggest how I achieve this?

Also how can I achieve the same using objectmanager not using factory method.

Can you suggest both ways on doing it.

Best Answer

protected $response;

public function __construct(
   \Magento\Framework\App\Response\Http $response
)
{
    $this->response = $response;
}

 $this->response->setRedirect('url here');

reference