Advertising sustains the DA. Ads are hidden for members. Join today

Contributed module documentation

Drupal Js Path

Last updated on
5 August 2023

Drupal JS Path module usage is explained below

  1. Drupal.path('entity.node.canonical', {'node': node.id})
  2. 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

  1. {path: '/node/7'}
  2. {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: