Drupal Js Path
Last updated on
5 August 2023
Drupal JS Path module usage is explained below
- Drupal.path('entity.node.canonical', {'node': node.id})
- Drupal.alias('entity.node.canonical', {'node': node.id})
The first parameter would be the route name like the one provided above and the second parameter would be parameters which will be required to that route.
Responses for the above would be like this
- {path: '/node/7'}
- {path: '/unicorn'}
If we want an absolute URL or other options that to be added to that route, we need to add it as a third parameter
array $options: (optional) An associative array of additional URL options, with the following elements:
- 'query': An array of query key/value pairs (without any URL-encoding) to append to the URL.
- 'fragment': A fragment identifier (named anchor) to append to the URL. Do not include the leading '#' character.
- 'absolute': Defaults to FALSE. Whether to force the output to be an absolute link (beginning with http:). Useful for links that will be displayed outside the site, such as in an RSS feed.
- 'attributes': An associative array of HTML attributes that will be added to the anchor tag if you use the \Drupal\Core\Link class to make the link.
- 'language': An optional language object used to look up the alias for the URL. If $options['language'] is omitted, it defaults to the current language for the language type LanguageInterface::TYPE_URL.
- 'https': Whether this URL should point to a secure location. If not defined, the current scheme is used, so the user stays on HTTP or HTTPS respectively. TRUE enforces HTTPS and FALSE enforces HTTP.
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.