I've seen it often that the path is simply built by concatenating strings. But if you want to do it in a D8 way, then use the route from the view.
You can investigate the routes with Drupal Console on the command line or the Devel module in UI, where you'll find the routes in /devel/routes.
For example this view:
ROUTE NAME: view.testview.page_1 PATH: /testview/{arg_0}/{arg_1}
When you know the route name and the arguments for the contextual filters you can build the URL:
use Drupal\Core\Url;
$url = Url::fromRoute('view.testview.page_1', [
'arg_0' => $arg1,
'arg_1' => $arg2,
]);
The URL is an object, which you put in a render array, for example in a link element. If needed you can get the path as string with the method ->toString()
, but this should be avoided.
If you want to use the route in a field rewrite you can use the twig function url()
in a field replacement pattern:
<a href="{{ url('view.testview.page_1', {'arg_0': field_example__value}) }}">Link to Testview</a>