Skip to content

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

DruxtRouterStore

View source on GitHub

DruxtRouterStore

Vuex module, registered under the druxtRouter namespace. The druxtRouter Vuex module.

Provides a Vuex state object, mutations and actions for interacting with the Drupal JSON:API.

See: /explanation/druxt-store


get(path) ⇒ object

Get route and redirect information.

  • Dispatches druxtRouter/getRoute action.
  • Sets the active route.
  • Sets the active redirect.
    Vuex Action => Mutates state propertyroute

Kind: action method of druxtRouter
Returns: object - The route and redirect information.

ParamTypeDescription
pathstringThe router path.

Example

const { redirect, route } = await this.$store.dispatch('druxtRouter/get', '/')

getRoute(path) ⇒ object

Get Route.

  • Executes query against Drupal Decoupled router.
  • Caches result in the Vuex store.
  • Returns cached result from Vuex store when available.
    Vuex Action => Mutates state propertyroute

Kind: action method of druxtRouter
Returns: object - The route object.

ParamTypeDescription
pathstringThe route path.

Example

const route = await this.$store.dispatch('druxtRouter/getRoute', '/')

getEntity(context, query) ⇒ object

Deprecated in druxt-router:0.18.0, removed from druxt-router:2.0.0. Use the DruxtStore druxt/getResource action instead.

Get Entity.

  • Executes query against Drupal JSON:API.
  • Caches result in the Vuex store.
  • Returns cached result from Vuex store when available.
    Vuex Action => Mutates state propertyentities

Kind: action method of druxtRouter
Returns: object - The Drupal entity JSON:API resource data.
See

ParamTypeDescription
contextobjectThe Vuex action context.
context.commitfunctionCommits mutations to the store.
context.stateobjectThe Vuex module state.
queryobjectThe JSON:API resource query.

Example

const entity = await this.$store.dispatch('druxtRouter/getEntity', { type: 'node--article', id })

getResources(app, payload) ⇒ Array.<object>

Deprecated in druxt-router:0.18.0, removed from druxt-router:2.0.0. Use the DruxtStore druxt/getCollection action instead.

Get multiple resources.
Vuex Action

Kind: action method of druxtRouter
Returns: Array.<object> - Array of Drupal JSON:API resource data.
See

ParamTypeDescription
appobjectThe Nuxt app context.
payloadgetResourcesContextThe action parameters.

Example

// Load currently published Articles.
const query = new DrupalJsonApiParams()
query.addFilter('status', '1')
const resources = await this.$store.dispatch('druxtRouter/getResources', {
  resource: 'node--article',
  query
})

state : object

Vuex State object.

Read only: true
Properties

NameTypeDescription
entitiesobjectDrupal entity store.
redirectboolean | objectActive redirect.
routeobjectActive route.
routesobjectRoute store.

setRedirect

Sets the active redirect.

Kind: mutation method of druxtRouter

ParamTypeDescription
stateobjectThe Vuex state object.
redirectobjectThe Redirect object.

Example

this.$store.commit('druxtRouter/setRedirect', redirect)

addRoute

Adds the supplied route to the Vuex state object.

Kind: mutation method of druxtRouter

ParamTypeDescription
stateobjectThe Vuex state object.
payloadaddRoutePayloadThe mutation payload.

Example

this.$store.commit('druxtRouter/addRoute', { path, route })

setRoute

Sets the active route by path.

Kind: mutation method of druxtRouter

ParamTypeDescription
stateobjectThe Vuex state object.
pathstringThe route path

Example

this.$store.commit('druxtRouter/setRoute', '/')

addEntity

Deprecated in druxt-router:0.18.0, removed from druxt-router:2.0.0. Use the DruxtStore druxt/addResource mutation instead.

Adds specified Drupal entity JSON:API resource data to the Vuex state object.

Kind: mutation method of druxtRouter
See

ParamTypeDescription
stateobjectThe Vuex state object.
entityobjectThe Drupal entity JSON:API resource data.

Example

this.$store.commit('druxtRouter/addEntity', entity)

addRoutePayload : object

Parameters for the addRoute mutation.

Kind: global typedef

ParamTypeDescription
pathstringThe route path.
routeobjectThe route object.

Example

{
  path: '/',
  route: {}
}

getResourcesContext : object

Parameters for the getResources action.

Kind: global typedef

ParamTypeDescription
resourcestringThe JSON:API resource type.
querystring | objectA JSON:API query string or object.

Example

{
  resource: 'node--article',
  query: new DrupalJsonApiParams().addFilter('status', '1')
}