DruxtRouter
View source on GitHubModules
- DruxtRouter
The DruxtRouter component renders a Drupal decoupled route, or path, using the appropriate Druxt component.
For instance, using the path
/node/1would render 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> - ComponentData :
object - WrapperData :
object
DruxtRouter
The DruxtRouter component renders a Drupal decoupled route, or path, using the appropriate Druxt component.
For instance, using the path /node/1 would render 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>
- 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 : string
The resource langcode.
Kind: static property of props
Default: "undefined"
Example
<DruxtRouter langcode="en" />
.v-model : object
The Router object, used to determine the resolved route component.
Setting this value will bypass the JSON:API.
Kind: static property of props
Default: () => undefined
.wrapper : (boolean | object)
The wrapper component configuration.
Used to set the wrapper component, class, style and propsData.
Kind: static property of props
Default: () => undefined
Example
<DruxtRouter
:wrapper="{
component: 'MyWrapper',
class: 'wrapper',
propsData: { foo: 'bar' }
}"
/>
.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
| Param | Type | Description |
|---|---|---|
| context | object | The module component ViewModel. |
.fetchConfig()
Fetch the decoupled route.
Kind: static method of druxt
.propsData(context) ⇒ PropsData
Provides propsData for the DruxtWrapper.
Kind: static method of druxt
| Param | Type | Description |
|---|---|---|
| context | object | The module component ViewModel. |
| context.$route | object | The current Vue Router route object. |
.slots() ⇒ 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.
Example (DruxtRouterModule.vue)
<template>
<div>
<slot name="debug" />
{{ route.props }}
</div>
</template>
.middleware()
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
| Param | Type | Description |
|---|---|---|
| root0.$druxt | object | The Druxt Nuxt context plugin instance. |
Example
export default {
druxt: {
router: {
middleware: false
}
}
}
.data()
Kind: static method of DruxtRouter
Properties
| Name | Type | Description |
|---|---|---|
| model | object | The model object. |
.head()
Nuxt head method.
- Sets the page title.
- Sets the canonical link.
Kind: static method of DruxtRouter
Todo
- Improve metatag support.
.error()
Sets the component to render a DruxtDebug error message.
Kind: instance method of DruxtRouter
.getModuleComponents() ⇒ Components
Get list of module wrapper components.
Kind: instance method of DruxtRouter
.getModulePropsData() ⇒ object
Get module propsData via modules druxt.propsData() callback.
Kind: instance method of DruxtRouter
Example
{
bar: 'foo',
foo: 'bar',
}
.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
| Param | Type | Description |
|---|---|---|
| component | string | The 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/dist/components/DruxtModule.vue'
export default {
name: 'DruxtTestModule',
extends: DruxtModule,
async fetch() {
await DruxtModule.fetch.call(this)
}
druxt: {
componentOptions: () => ([['wrapper']]),
propsData: (ctx) => ({
bar: ctx.bar,
foo: ctx.foo,
}),
}
}
.lang() ⇒ 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.
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
| Param | Type | Description |
|---|---|---|
| path | string | The route path. |
| route | object | The 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
| Param | Type | Description |
|---|---|---|
| debug | function | A Debug component with a Path override field. |
| default | function | Default error handling. |
Example (DruxtRouterModule.vue)
<template>
<div>
<slot name="debug" />
{{ route.props }}
</div>
</template>
Components : Array.<object>
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| global | boolean | Component global registration state. |
| name | string | The component name. |
| parts | Array.<string> | The component naming parts. |
Example
[{
global: true,
pascal: 'DruxtTestModuleWrapper',
parts: ['Wrapper'],
}]
ComponentData : object
Kind: global typedef
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| $attrs | object | propsData not registered by the Wrapper component. | |
| is | string | "DruxtWrapper" | The Wrapper component name. |
| options | Array.<string> | The Wrapper component options. | |
| props | object | propsData registered by the Wrapper component. | |
| propsData | object | The component propsData object. | |
| settings | object | Druxt settings object provided by the Wrapper component. |
Example
{
$attrs: { bar: 'foo' },
is: 'DruxtTestModuleWrapper',
options: [
'DruxtTestModuleWrapper',
],
props: { foo: 'bar' },
propsData: {
bar: 'foo',
foo: 'bar',
},
settings: { fooBar: true },
}
WrapperData : object
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| druxt | object | Druxt settings object for use by Druxt module. |
| props | object | Registered props oject. |
Example
{
druxt: { fooBar: true },
props: {
foo: {
type: String,
default: '',
}
}
}