Is it possible to create a Link to a node with a hash in url (for opening a special Tab).

I use:

Link::createFromRoute('Title', 'entity.node.canonical', ['node' => 77]);

And I want to link to: "/node/77#example"

1 Answer 1


Please see public static function Link::createFromRoute

array $options: The options parameter takes exactly the same structure. See \Drupal\Core\Url::fromUri() for details.

You can pass a 4th argument as an array with a fragment key value:

Link::createFromRoute($this->t('Title'), 'entity.node.canonical', ['node' => 77], ['fragment' => 'example']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.