Skip to content

Drupal router for Nuxt, powered by the Drupal Decoupled Router module.

DruxtRouter

View source on GitHub

Modules

DruxtRouter

The DruxtRouter component renders a Drupal decoupled route, or path, using the appropriate Druxt component.

The path /node/1 renders a DruxtEntity component.

The Vue router path will be used if not path is defined.

Typedefs

ComponentOptions : Array.<array>

Provides the available naming options for the Wrapper component.

PropsData : object

Provides property data for use in the Wrapper component.

ScopedSlots : object

Provides scoped slots for use in the Wrapper component.

Components : Array.<object>

The list of candidate Wrapper components, with naming parts and global registration state.

ComponentData : object

The Wrapper component and propsData to be rendered.

WrapperData : object

Druxt settings and registered props retrieved from the Wrapper component.

DruxtRouter

The DruxtRouter component renders a Drupal decoupled route, or path, using the appropriate Druxt component.

The path /node/1 renders a DruxtEntity component.

The Vue router path will be used if not path is defined.

Example (Render using the Vue router path)

<DruxtRouter />

Example (Render a specified path)

<DruxtRouter path="/node/1" />

Example (Render the result of the model, bypasses Drupal backend)

<DruxtRouter v-model="route" />

Example (DruxtRouter Wrapper component boilerplate)

<template>
  <DruxtDebug :json="route" />
</template>

<script>
import { DruxtRouterMixin } from 'druxt-router'
export default {
  mixins: [DruxtRouterMixin]
}

Example (DruxtRouter with template injection)

<DruxtRouter>
  <template #default="{ route }">
    <!-- Do whatever you want here -->
    <DruxtDebug :json="route" open />
  </template>
</DruxtRouter>

.props

Kind: static property of DruxtRouter


.path : string

The Decoupled router path.

If not set, the Vue router value will be used instead.

Kind: static property of props
Example

<DruxtRouter path="/node/1" />

.value : object

The Router object, used to determine the resolved route component.

Setting this value will bypass the JSON:API.

Kind: static property of props
Model:


.langcode

The resource langcode.

Kind: static property of props
Example

<DruxtRouter langcode="en" />

.v-model

The Router object, used to determine the resolved route component.

Setting this value will bypass the JSON:API.

Kind: static property of props


.wrapper

The wrapper component configuration.

Used to set the wrapper component, class, style and propsData.

Kind: static property of props
Example

<DruxtRouter
  :wrapper="{
    component: 'BCard',
    class: 'article-card',
    propsData: { noBody: true }
  }"
/>

.route : object

The Decoupled router object.

Kind: static property of props


.computed

Kind: static property of DruxtRouter


.module : string

The route module.

Kind: static property of computed


.route : object

The route object.

Kind: static property of computed


.title : boolean | string

Route title.

Kind: static property of computed
Default: false


.props : object | string

Route component property data.

Kind: static property of computed
Default: false


.watch

Kind: static property of DruxtRouter


.path()

Re-fetch on update to Path prop.

Kind: static method of watch


.druxt

DruxtModule settings

Kind: static property of DruxtRouter


.template

Druxt development template tool configuration.

Kind: static property of druxt


.componentOptions(context) ⇒ ComponentOptions

Provides the available component naming options for the Druxt Wrapper.

Kind: static method of druxt

ParamTypeDescription
contextobjectThe module component ViewModel.
context.modulestring | falseThe route module, or false where the route has none.
context.routeobjectThe route object.

.fetchConfig()

Fetch the decoupled route.

Kind: static method of druxt


.propsData(context) ⇒ PropsData

Provides propsData for the DruxtWrapper.

Kind: static method of druxt

ParamTypeDescription
contextobjectThe module component ViewModel.
context.$routeobjectThe current Vue Router route object.
[context.path]stringThe Decoupled router path.
context.modelobject | undefinedThe route model, from the optional value prop.

.slots(h) ⇒ ScopedSlots

Provides the scoped slots object for the Module render function.

  • debug: A Debug component with a Path override field.
  • default: Default error handling.

Kind: static method of druxt
Returns: ScopedSlots - The Scoped slots object.

ParamTypeDescription
hfunctionThe Vue createElement function.

Example (DruxtRouterModule.vue)

<template>
  <div>
    <slot name="debug" />
    {{ route.props }}
  </div>
</template>

.middleware(context)

Nuxt middleware; gets and sets the current route, and processes redirects.

This can be disabled by setting the druxt.router.middleware option to false in nuxt.config.js

Kind: static method of DruxtRouter

ParamTypeDescription
contextobjectThe Nuxt context.
context.$druxtobjectThe Druxt Nuxt context plugin instance.
context.redirectfunctionThe Nuxt redirect method.
context.routeobjectThe current route.
context.storeobjectThe Vuex store.

Example

export default {
  druxt: {
    router: {
      middleware: false
    }
  }
}

.data(vm)

Kind: static method of DruxtRouter

ParamTypeDescription
vmobjectThe component ViewModel.
[vm.value]objectThe Router object, used to bypass the JSON:API.

Properties

NameTypeDescription
modelobject | undefinedThe route model, from the optional value prop.

Nuxt head method.

  • Sets the page title.
  • Sets the canonical link.

Kind: static method of DruxtRouter
Todo

  • Improve metatag support.

.error(err, [context])

Sets the component to render a DruxtDebug error message.

Kind: instance method of DruxtRouter

ParamTypeDescription
errobjectThe error object.
[context]objectError context; carries the wrapper component data where the failure knows it.

.getModuleComponents() ⇒ Components

Get list of module wrapper components.

Kind: instance method of DruxtRouter


.getModulePropsData(wrapperProps) ⇒ object

Get module propsData via modules druxt.propsData() callback.

Kind: instance method of DruxtRouter

ParamTypeDescription
wrapperPropsobjectProps registered by the Wrapper component.

Example

{
  $attrs: { entity: {}, fields: {}, langcode: 'en', schema: {} },
  props: { value: {} },
  propsData: { entity: {}, fields: {}, langcode: 'en', schema: {}, value: {} },
}

.getScopedSlots() ⇒ object

Gets a Druxt modules scoped slots, and if there's no default slots, provides a develop mode debug default or passes through to a default template.

Kind: instance method of DruxtRouter


.getWrapperData(component) ⇒ WrapperData

Get wrapper component data.

Kind: instance method of DruxtRouter

ParamTypeDescription
componentstringThe Wrapper component name.

.methods

Kind: static property of DruxtRouter


.fetch()

Loads the Druxt module data and applies a wrapper component as required.

Important: If your component has an existing fetch method, you must manually invoke the DruxtModule.fetch() hook.

Kind: static method of DruxtRouter
Example (Manually invoking DruxtModule.fetch().)

import DruxtModule from 'druxt/components/DruxtModule.vue'
export default {
  name: 'DruxtCustomModule',
  extends: DruxtModule,
  async fetch() {
    await DruxtModule.fetch.call(this)
  }
  druxt: {
    componentOptions: () => ([['Default']]),
    propsData: ({ model }) => ({ value: model }),
  }
}

.lang(vm) ⇒ string

The current language code: the langcode prop if set, otherwise the route's langcode metadata.

Used by Druxt modules to fetch the correct resource translation.

Kind: static method of DruxtRouter
Returns: string - The current language code.

ParamTypeDescription
vmobjectThe component ViewModel.
vm.langcodestringThe langcode prop.
vm.$routeobjectThe current route.

ComponentOptions : Array.<array>

Provides the available naming options for the Wrapper component.

Kind: global typedef
Example

[
  'DruxtRouter[Module][IsFront?][Langcode]',
  'DruxtRouter[Module][IsFront?]',
  'DruxtRouter[Module][Langcode]',
  'DruxtRouter[Module]',
  'DruxtRouter[Default][Langcode]',
  'DruxtRouter[Default]',
]

Example (Entity route)

[
  'DruxtRouterEntityFrontEn',
  'DruxtRouterEntityFront',
  'DruxtRouterEntityEn',
  'DruxtRouterEntity',
  'DruxtRouterDefaultEn',
  'DruxtRouterDefault'
]

PropsData : object

Provides property data for use in the Wrapper component.

Kind: global typedef

ParamTypeDescription
pathstringThe route path.
routeobjectThe Decoupled Router object.

Example

{
  path: '/',
  route: {
    canonical: 'https://demo-api.druxtjs.org/en/node',
    component: 'druxt-view',
    error: false,
    isHomePath: true,
    jsonapi: {},
    label: 'Home',
    props: {},
    redirect: false,
    resolvedPath: '/en/node',
    type: 'views',
  }
}

ScopedSlots : object

Provides scoped slots for use in the Wrapper component.

Kind: global typedef

ParamTypeDescription
debugfunctionA Debug component with a Path override field.
defaultfunctionDefault error handling.

Example (DruxtRouterModule.vue)

<template>
  <div>
    <slot name="debug" />
    {{ route.props }}
  </div>
</template>

Components : Array.<object>

The list of candidate Wrapper components, with naming parts and global registration state.

Kind: global typedef
Properties

NameTypeDescription
globalbooleanComponent global registration state.
namestringThe component name.
partsArray.<string>The component naming parts.

Example

[{
  global: true,
  name: 'DruxtEntityNodeArticleDefault',
  parts: ['NodeArticle', 'Default'],
}]

ComponentData : object

The Wrapper component and propsData to be rendered.

Kind: global typedef
Properties

NameTypeDefaultDescription
$attrsobjectpropsData not registered by the Wrapper component.
isstring"DruxtWrapper"The Wrapper component name.
optionsArray.<string>The Wrapper component options.
propsobjectpropsData registered by the Wrapper component.
propsDataobjectThe component propsData object.
settingsobjectDruxt settings object provided by the Wrapper component.

Example

{
  $attrs: { entity: {}, fields: {}, schema: {} },
  is: 'DruxtEntityNodeArticleDefault',
  options: [
    'DruxtEntityNodeArticleDefault',
    'DruxtEntityDefault',
  ],
  props: { value: {} },
  propsData: {
    entity: {},
    fields: {},
    schema: {},
    value: {},
  },
  settings: { query: {} },
}

WrapperData : object

Druxt settings and registered props retrieved from the Wrapper component.

Kind: global typedef
Properties

NameTypeDescription
druxtobjectDruxt settings object for use by Druxt module.
propsobjectRegistered props oject.

Example

{
  druxt: { query: { fields: ['path', 'title'] } },
  props: {
    value: {
      type: Object,
      default: () => ({}),
    }
  }
}