druxt-router
Advanced tools
Comparing version 0.26.1 to 0.27.0
import { DruxtClient } from 'druxt'; | ||
import Url from 'url-parse'; | ||
import Vue from 'vue'; | ||
import { mapState, mapActions } from 'vuex'; | ||
@@ -15,2 +16,3 @@ | ||
props: (route) => ({ | ||
langcode: route.entity.langcode, | ||
type: route.jsonapi.resourceName, | ||
@@ -27,2 +29,3 @@ uuid: route.entity.uuid | ||
displayId: route.view.display_id, | ||
langcode: route.view.langcode || void 0, | ||
type: route.jsonapi.resourceName, | ||
@@ -65,2 +68,3 @@ uuid: route.view.uuid, | ||
getRedirect(path, route = {}) { | ||
const prefix = (route.props || {}).langcode || ""; | ||
if (((route.redirect || [])[0] || {}).to) { | ||
@@ -71,4 +75,5 @@ return route.redirect[0].to; | ||
if (route.isHomePath) { | ||
if (url.pathname !== "/") { | ||
return "/"; | ||
const homePath = prefix ? `/${prefix}` : "/"; | ||
if (!(url.pathname === homePath || url.pathname === `${homePath}/`)) { | ||
return homePath; | ||
} | ||
@@ -106,6 +111,6 @@ return false; | ||
async getResourceByRoute(route) { | ||
const resource = await this.druxt.getResource(route.jsonapi.resourceName, route.entity.uuid); | ||
const resource = await this.druxt.getResource(route.jsonapi.resourceName, route.entity.uuid, route.prefix); | ||
return resource.data || false; | ||
} | ||
async getRoute(path) { | ||
async getRoute(path = "/") { | ||
const url = `/router/translate-path?path=${path}`; | ||
@@ -132,3 +137,4 @@ const response = await this.druxt.get(url, { | ||
redirect: data.redirect, | ||
resolvedPath: Url(data.resolved).pathname | ||
resolvedPath: Url(data.resolved).pathname, | ||
entity: data.entity | ||
}; | ||
@@ -199,3 +205,3 @@ for (const key in this.options.types) { | ||
} | ||
state.routes[path] = route; | ||
Vue.set(state.routes, path, route); | ||
}, | ||
@@ -299,2 +305,6 @@ setRoute(state, path) { | ||
props: { | ||
langcode: { | ||
type: String, | ||
default: void 0 | ||
}, | ||
path: { | ||
@@ -301,0 +311,0 @@ type: String, |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const Url = require('url-parse'); | ||
const Vue = require('vue'); | ||
const vuex = require('vuex'); | ||
@@ -13,2 +14,3 @@ | ||
const Url__default = /*#__PURE__*/_interopDefaultLegacy(Url); | ||
const Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue); | ||
@@ -25,2 +27,3 @@ class DruxtRouter { | ||
props: (route) => ({ | ||
langcode: route.entity.langcode, | ||
type: route.jsonapi.resourceName, | ||
@@ -37,2 +40,3 @@ uuid: route.entity.uuid | ||
displayId: route.view.display_id, | ||
langcode: route.view.langcode || void 0, | ||
type: route.jsonapi.resourceName, | ||
@@ -75,9 +79,11 @@ uuid: route.view.uuid, | ||
getRedirect(path, route = {}) { | ||
const prefix = (route.props || {}).langcode || ""; | ||
if (((route.redirect || [])[0] || {}).to) { | ||
return route.redirect[0].to; | ||
} | ||
const url = Url__default['default'](path); | ||
const url = Url__default["default"](path); | ||
if (route.isHomePath) { | ||
if (url.pathname !== "/") { | ||
return "/"; | ||
const homePath = prefix ? `/${prefix}` : "/"; | ||
if (!(url.pathname === homePath || url.pathname === `${homePath}/`)) { | ||
return homePath; | ||
} | ||
@@ -87,3 +93,3 @@ return false; | ||
if (typeof route.canonical === "string") { | ||
const canonicalUrl = new Url__default['default'](route.canonical); | ||
const canonicalUrl = new Url__default["default"](route.canonical); | ||
if (url.pathname !== canonicalUrl.pathname) { | ||
@@ -116,6 +122,6 @@ return canonicalUrl.pathname; | ||
async getResourceByRoute(route) { | ||
const resource = await this.druxt.getResource(route.jsonapi.resourceName, route.entity.uuid); | ||
const resource = await this.druxt.getResource(route.jsonapi.resourceName, route.entity.uuid, route.prefix); | ||
return resource.data || false; | ||
} | ||
async getRoute(path) { | ||
async getRoute(path = "/") { | ||
const url = `/router/translate-path?path=${path}`; | ||
@@ -142,3 +148,4 @@ const response = await this.druxt.get(url, { | ||
redirect: data.redirect, | ||
resolvedPath: Url__default['default'](data.resolved).pathname | ||
resolvedPath: Url__default["default"](data.resolved).pathname, | ||
entity: data.entity | ||
}; | ||
@@ -209,3 +216,3 @@ for (const key in this.options.types) { | ||
} | ||
state.routes[path] = route; | ||
Vue__default["default"].set(state.routes, path, route); | ||
}, | ||
@@ -309,2 +316,6 @@ setRoute(state, path) { | ||
props: { | ||
langcode: { | ||
type: String, | ||
default: void 0 | ||
}, | ||
path: { | ||
@@ -311,0 +322,0 @@ type: String, |
@@ -30,2 +30,2 @@ /** | ||
export default DruxtRouterNuxtModule; | ||
export { DruxtRouterNuxtModule as default }; |
@@ -7,2 +7,4 @@ 'use strict'; | ||
const path = require('path'); | ||
const drupalJsonapiParams = require('drupal-jsonapi-params'); | ||
const druxt = require('druxt'); | ||
@@ -24,2 +26,5 @@ const DruxtRouterNuxtModule = async function(moduleOptions = {}) { | ||
if (options.router.wildcard) { | ||
if (!options.router.pages) { | ||
this.nuxt.hook("build:before", () => this.nuxt.options.build.createRoutes = () => []); | ||
} | ||
this.addTemplate({ | ||
@@ -30,7 +35,23 @@ src: path.resolve(__dirname, "../templates/component.js"), | ||
}); | ||
this.extendRoutes((routes, resolve2) => { | ||
const druxt$1 = new druxt.DruxtClient(options.baseUrl, { | ||
...options, | ||
proxy: { ...options.proxy || {}, api: false } | ||
}); | ||
const resourceType = "configurable_language--configurable_language"; | ||
const query = new drupalJsonapiParams.DrupalJsonApiParams().addFields(resourceType, ["drupal_internal__id"]); | ||
const languages = (await druxt$1.getCollectionAll(resourceType, query) || []).map((o) => o.data).flat().filter((o) => !["und", "zxx"].includes(o.attributes.drupal_internal__id)); | ||
this.extendRoutes((routes) => { | ||
languages.forEach((o) => { | ||
routes.push({ | ||
name: `druxt-router__${o.attributes.drupal_internal__id}`, | ||
path: `/${o.attributes.drupal_internal__id}*`, | ||
component: path.resolve(this.options.buildDir, "components/druxt-router.js"), | ||
chunkName: "druxt-router", | ||
meta: { langcode: o.attributes.drupal_internal__id } | ||
}); | ||
}); | ||
routes.push({ | ||
name: "druxt-router", | ||
path: "*", | ||
component: resolve2(this.options.buildDir, "components/druxt-router.js"), | ||
component: path.resolve(this.options.buildDir, "components/druxt-router.js"), | ||
chunkName: "druxt-router" | ||
@@ -40,5 +61,2 @@ }); | ||
} | ||
if (options.router.wildcard && !options.router.pages) { | ||
this.nuxt.hook("build:before", () => this.nuxt.options.build.createRoutes = () => []); | ||
} | ||
this.addPlugin({ | ||
@@ -66,2 +84,2 @@ src: path.resolve(__dirname, "../templates/plugin.js"), | ||
exports.default = DruxtRouterNuxtModule; | ||
exports["default"] = DruxtRouterNuxtModule; |
{ | ||
"name": "druxt-router", | ||
"version": "0.26.1", | ||
"version": "0.27.0", | ||
"description": "Drupal router for Nuxt, powered by the Drupal Decoupled Router module.", | ||
@@ -45,5 +45,11 @@ "keywords": [ | ||
"dependencies": { | ||
"druxt": "^0.18.0", | ||
"url-parse": "^1.4.7" | ||
"druxt": "^0.19.0", | ||
"url-parse": "^1.5.10" | ||
}, | ||
"devDependencies": { | ||
"vue-router": "^3.5.4" | ||
}, | ||
"peerDependencies": { | ||
"drupal-jsonapi-params": "*" | ||
}, | ||
"optionalDependencies": { | ||
@@ -50,0 +56,0 @@ "vue": "^2.6.14", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38217
837
5
1
+ Addeddruxt@0.19.3(transitive)
- Removeddruxt@0.18.3(transitive)
Updateddruxt@^0.19.0
Updatedurl-parse@^1.5.10