druxt-router 0.30.0 → 0.31.1-dev.20260920043715
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -33
- package/banner.svg +1 -0
- package/dist/components/DruxtRouter.vue +29 -10
- package/dist/components/index.mjs +2 -2
- package/dist/druxt-router.esm.js +10 -8
- package/dist/druxt-router.ssr.js +10 -8
- package/icon.svg +5 -0
- package/nuxt/index.d.ts +14 -4
- package/nuxt/index.js +2 -1
- package/package.json +8 -4
- package/templates/plugin.js +5 -0
package/README.md
CHANGED
|
@@ -1,58 +1,124 @@
|
|
|
1
|
-
|
|
1
|
+
<img src="./banner.svg" alt="DruxtRouter provides Drupal routing for Nuxt, via Decoupled Router">
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[](https://github.com/druxt/druxt.js/actions/workflows/ci.yml)
|
|
6
|
+
[](https://snyk.io/test/github/druxt/druxt.js?targetFile=package.json)
|
|
7
|
+
[](https://codecov.io/gh/druxt/druxt.js)
|
|
6
8
|
|
|
7
9
|
> Drupal router for Nuxt, powered by the Drupal Decoupled Router module.
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
DruxtRouter connects Nuxt routing to Drupal routing. A wildcard route catches
|
|
12
|
+
requests, resolves them through Drupal's
|
|
13
|
+
[Decoupled Router](https://www.drupal.org/project/decoupled_router) with path
|
|
14
|
+
aliases and redirects included, and renders the matching Druxt component for
|
|
15
|
+
the resolved entity or view. Your Nuxt `pages/` directory keeps working
|
|
16
|
+
alongside it, so a custom page can take over any route.
|
|
14
17
|
|
|
15
18
|
## Features
|
|
16
19
|
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
20
|
+
- Vue.js components:
|
|
21
|
+
- **DruxtRouter** renders a Druxt component for the resolved Decoupled route
|
|
22
|
+
- Route providers:
|
|
23
|
+
- **Content entity** routes resolve **DruxtEntity** components
|
|
24
|
+
- **Drupal Views** page routes resolve **DruxtView** components
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
> Included with [`druxt-site`](https://druxtjs.org/modules/site). Install it separately only when composing modules yourself.
|
|
31
|
+
|
|
32
|
+
1. Install the package:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
npm i druxt-router
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Add the module to `nuxt.config.js`:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
export default {
|
|
42
|
+
modules: ['druxt-router/nuxt'],
|
|
43
|
+
};
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Options
|
|
47
|
+
|
|
48
|
+
- `druxt.router.middleware`
|
|
49
|
+
|
|
50
|
+
Type: `boolean`
|
|
51
|
+
Default: `true`
|
|
52
|
+
|
|
53
|
+
Controls whether to execute the Route page middleware and process redirects.
|
|
54
|
+
|
|
55
|
+
- `druxt.router.pages`
|
|
21
56
|
|
|
22
|
-
|
|
57
|
+
Type: `boolean`
|
|
58
|
+
Default: `true` if **pages/** directory exists, else `false`
|
|
23
59
|
|
|
24
|
-
|
|
60
|
+
Controls whether the Nuxt **pages/** directory is used to generate routes.
|
|
25
61
|
|
|
26
|
-
|
|
62
|
+
- `druxt.router.wildcard`
|
|
27
63
|
|
|
28
|
-
|
|
64
|
+
Type: `boolean`
|
|
65
|
+
Default: `true`
|
|
29
66
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
67
|
+
Controls whether the wildcard route should be installed into the Nuxt/Vue router.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Vue.js components
|
|
72
|
+
|
|
73
|
+
### DruxtRouter
|
|
74
|
+
|
|
75
|
+
Renders a Druxt module router component based on the resolved route provided by the Drupal Decoupled Router module.
|
|
76
|
+
|
|
77
|
+
```vue
|
|
78
|
+
<DruxtRouter path="/" />
|
|
37
79
|
```
|
|
38
80
|
|
|
81
|
+
If no Path is provided, the component will default to the Vue router fullpath.
|
|
82
|
+
|
|
83
|
+
- For more details, refer to the [DruxtRouter API documentation](https://druxtjs.org/api/packages/router/components/DruxtRouter).
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Deprecations
|
|
88
|
+
|
|
89
|
+
Retired `DruxtRouter` client pass-through methods and `druxtRouter` store
|
|
90
|
+
resource members, with their replacements, are listed on the
|
|
91
|
+
[deprecations page](https://druxtjs.org/modules/router/deprecations).
|
|
92
|
+
|
|
93
|
+
- For the routing API itself, see the
|
|
94
|
+
[DruxtRouter API documentation](https://druxtjs.org/api/packages/router/router).
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
39
98
|
## Options
|
|
40
99
|
|
|
41
100
|
### Druxt Router options
|
|
42
101
|
|
|
43
102
|
These options are specific to this module.
|
|
44
103
|
|
|
45
|
-
| Option
|
|
46
|
-
|
|
|
47
|
-
| `router.
|
|
48
|
-
| `router.
|
|
104
|
+
| Option | Type | Required | Default | Description |
|
|
105
|
+
| ------------------- | --------- | -------- | --------------------------- | ------------------------------------------------------- |
|
|
106
|
+
| `router.middleware` | `boolean` | No | `true` | Whether to run the Route page middleware and redirects. |
|
|
107
|
+
| `router.pages` | `boolean` | No | `true` if **pages/** exists | Whether to parse the Nuxt `pages/` directory. |
|
|
108
|
+
| `router.wildcard` | `boolean` | No | `true` | Whether to install the wildcard route. |
|
|
49
109
|
|
|
50
110
|
### Base Druxt options
|
|
51
111
|
|
|
52
112
|
These options are available to all DruxtJS modules.
|
|
53
113
|
|
|
54
|
-
| Option
|
|
55
|
-
|
|
|
56
|
-
| `axios`
|
|
57
|
-
| `baseUrl`
|
|
58
|
-
| `endpoint` | `string` | No
|
|
114
|
+
| Option | Type | Required | Default | Description |
|
|
115
|
+
| ---------- | -------- | -------- | ---------- | ---------------------------------------------------------------------------- |
|
|
116
|
+
| `axios` | `object` | No | `{}` | [Axios instance settings](https://github.com/axios/axios#axioscreateconfig). |
|
|
117
|
+
| `baseUrl` | `string` | Yes | `null` | Base URL for the Drupal installation. |
|
|
118
|
+
| `endpoint` | `string` | No | `/jsonapi` | JSON:API Endpoint of the Drupal installation. |
|
|
119
|
+
|
|
120
|
+
## Links
|
|
121
|
+
|
|
122
|
+
- DruxtJS: https://druxtjs.org
|
|
123
|
+
- Documentation: https://druxtjs.org/modules/router
|
|
124
|
+
- Community Discord server: https://discord.druxtjs.org
|
package/banner.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 320" width="1280" height="320" role="img" aria-label="druxt-router: Drupal routing for Nuxt, via Decoupled Router."><defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#1f2937"/><stop offset="0.7" stop-color="#2f495e"/><stop offset="1" stop-color="#36566e"/></linearGradient></defs><rect width="1280" height="320" rx="16" fill="url(#g)"/><rect x="250" y="85" width="150" height="150" rx="32" fill="rgba(229,236,241,0.07)"/><g transform="translate(277,112) scale(4)" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3.5 18.25a2.25 2.25 0 1 0 4.5 0a2.25 2.25 0 1 0 -4.5 0" stroke="#7cc5f1"/><path d="M7.4 16.6c3.2-2.6 1.4-6.1 4.4-8.1 1.3-.87 2.5-.95 4.1-1.05" stroke="#7cc5f1"/><path d="M16 5.75a2.25 2.25 0 1 0 4.5 0a2.25 2.25 0 1 0 -4.5 0" stroke="#68cb9f"/></g><text x="440" y="150" style="font-family:ui-sans-serif,system-ui,sans-serif" font-size="64" font-weight="700" letter-spacing="-1" fill="#eef2f6">Router</text><text x="688" y="150" style="font-family:ui-monospace,Menlo,Consolas,monospace" font-size="26" fill="#7cc5f1">druxt-router</text><text x="440" y="196" style="font-family:ui-sans-serif,system-ui,sans-serif" font-size="25" fill="rgba(229,236,241,0.75)">Drupal routing for Nuxt, via Decoupled Router.</text><g transform="translate(440,236) scale(0.0994)"><path d="M139 330l-1-2c-2-4-2-8-1-13H29L189 31l67 121 22-16-67-121c-1-2-9-14-22-14-6 0-15 2-22 15L5 303c-1 3-8 16-2 27 4 6 10 12 24 12h136c-14 0-21-6-24-12z" fill="#3498DB"/><path d="M447 304L317 70c-2-2-9-15-22-15-6 0-15 3-22 15l-17 28v54l39-67 129 230h-49a23 23 0 0 1-2 14l-1 1c-6 11-21 12-23 12h76c3 0 17-1 24-12 3-5 5-14-2-26z" fill="#108775"/><path d="M376 330v-1l1-2c1-4 2-8 1-12l-4-12-102-178-15-27h-1l-15 27-102 178-4 12a24 24 0 0 0 2 15c4 6 10 12 24 12h190c3 0 18-1 25-12zM256 152l93 163H163l93-163z" fill="#E5ECF1"/></g><text x="492" y="260" style="font-family:ui-sans-serif,system-ui,sans-serif" font-size="17" font-weight="600" fill="rgba(229,236,241,0.85)">druxtjs.org</text></svg>
|
|
@@ -6,9 +6,9 @@ import DruxtModule from 'druxt/dist/components/DruxtModule.vue'
|
|
|
6
6
|
* The DruxtRouter component renders a Drupal decoupled route, or path, using
|
|
7
7
|
* the appropriate Druxt component.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* The path `/node/1` renders a DruxtEntity component.
|
|
10
10
|
*
|
|
11
|
-
* The Vue router path
|
|
11
|
+
* The Vue router path is used if no path is given.
|
|
12
12
|
*
|
|
13
13
|
* @example <caption>Render using the Vue router path</caption> @lang vue
|
|
14
14
|
* <DruxtRouter />
|
|
@@ -30,7 +30,7 @@ import DruxtModule from 'druxt/dist/components/DruxtModule.vue'
|
|
|
30
30
|
* mixins: [DruxtRouterMixin]
|
|
31
31
|
* }
|
|
32
32
|
*
|
|
33
|
-
* @example <caption>DruxtRouter
|
|
33
|
+
* @example <caption>DruxtRouter default slot (template injection)</caption> @lang vue
|
|
34
34
|
* <DruxtRouter>
|
|
35
35
|
* <template #default="{ route }">
|
|
36
36
|
* <!-- Do whatever you want here -->
|
|
@@ -49,6 +49,12 @@ export default {
|
|
|
49
49
|
* This can be disabled by setting the `druxt.router.middleware` option to
|
|
50
50
|
* `false` in `nuxt.config.js`
|
|
51
51
|
*
|
|
52
|
+
* @param {object} context - The Nuxt context.
|
|
53
|
+
* @param {object} context.$druxt - The Druxt Nuxt context plugin instance.
|
|
54
|
+
* @param {Function} context.error - The Nuxt error method.
|
|
55
|
+
* @param {Function} context.redirect - The Nuxt redirect method.
|
|
56
|
+
* @param {object} context.route - The current route.
|
|
57
|
+
* @param {object} context.store - The Vuex store.
|
|
52
58
|
* @example @lang js
|
|
53
59
|
* export default {
|
|
54
60
|
* druxt: {
|
|
@@ -58,7 +64,7 @@ export default {
|
|
|
58
64
|
* }
|
|
59
65
|
* }
|
|
60
66
|
*/
|
|
61
|
-
async middleware ({ $druxt, redirect, route, store }) {
|
|
67
|
+
async middleware ({ $druxt, error, redirect, route, store }) {
|
|
62
68
|
// Ensure Router middleware is enabled.
|
|
63
69
|
if (typeof ($druxt.settings.router || {}).middleware !== 'undefined' && !$druxt.settings.router.middleware) {
|
|
64
70
|
return
|
|
@@ -67,6 +73,11 @@ export default {
|
|
|
67
73
|
// Get and set the current route and redirect information.
|
|
68
74
|
const result = await store.dispatch('druxtRouter/get', route.fullPath)
|
|
69
75
|
|
|
76
|
+
// Render the Nuxt error page for route errors, e.g. 403 and 404.
|
|
77
|
+
if (result.error) {
|
|
78
|
+
return error(result.error)
|
|
79
|
+
}
|
|
80
|
+
|
|
70
81
|
// Process redirect.
|
|
71
82
|
if (result.redirect) {
|
|
72
83
|
redirect(result.redirect)
|
|
@@ -105,7 +116,9 @@ export default {
|
|
|
105
116
|
},
|
|
106
117
|
|
|
107
118
|
/**
|
|
108
|
-
* @
|
|
119
|
+
* @param {object} vm - The component ViewModel.
|
|
120
|
+
* @param {object} [vm.value] - The Router object, used to bypass the JSON:API.
|
|
121
|
+
* @property {object|undefined} model - The route model, from the optional value prop.
|
|
109
122
|
*/
|
|
110
123
|
data: ({ value }) => ({
|
|
111
124
|
debug: {
|
|
@@ -196,6 +209,8 @@ export default {
|
|
|
196
209
|
* Provides the available component naming options for the Druxt Wrapper.
|
|
197
210
|
*
|
|
198
211
|
* @param {object} context - The module component ViewModel.
|
|
212
|
+
* @param {string|false} context.module - The route module, or false where the route has none.
|
|
213
|
+
* @param {object} context.route - The route object.
|
|
199
214
|
* @returns {ComponentOptions}
|
|
200
215
|
*/
|
|
201
216
|
componentOptions: ({ module, route }) => [
|
|
@@ -233,6 +248,9 @@ export default {
|
|
|
233
248
|
* Provides propsData for the DruxtWrapper.
|
|
234
249
|
*
|
|
235
250
|
* @param {object} context - The module component ViewModel.
|
|
251
|
+
* @param {object} context.$route - The current Vue Router route object.
|
|
252
|
+
* @param {string} [context.path] - The Decoupled router path.
|
|
253
|
+
* @param {object|undefined} context.model - The route model, from the optional value prop.
|
|
236
254
|
* @returns {PropsData}
|
|
237
255
|
*/
|
|
238
256
|
propsData: ({ $route, path, model }) => ({
|
|
@@ -254,12 +272,13 @@ export default {
|
|
|
254
272
|
* </div>
|
|
255
273
|
* </template>
|
|
256
274
|
*
|
|
275
|
+
* @param {Function} h - The Vue createElement function.
|
|
257
276
|
* @return {ScopedSlots} The Scoped slots object.
|
|
258
277
|
*/
|
|
259
278
|
slots(h) {
|
|
260
279
|
const scopedSlots = {}
|
|
261
280
|
|
|
262
|
-
// Provide
|
|
281
|
+
// Provide default error message.
|
|
263
282
|
if (this.model.error) {
|
|
264
283
|
scopedSlots.default = () => h('div', [
|
|
265
284
|
h('h1', [`Error ${this.model.error.statusCode}`]),
|
|
@@ -283,7 +302,7 @@ export default {
|
|
|
283
302
|
}
|
|
284
303
|
|
|
285
304
|
/**
|
|
286
|
-
* Provides the available naming options for the
|
|
305
|
+
* Provides the available naming options for the wrapper component.
|
|
287
306
|
*
|
|
288
307
|
* @typedef {array[]} ComponentOptions
|
|
289
308
|
*
|
|
@@ -309,7 +328,7 @@ export default {
|
|
|
309
328
|
*/
|
|
310
329
|
|
|
311
330
|
/**
|
|
312
|
-
* Provides property data for use in the
|
|
331
|
+
* Provides property data for use in the wrapper component.
|
|
313
332
|
*
|
|
314
333
|
* @typedef {object} PropsData
|
|
315
334
|
* @param {string} path - The route path.
|
|
@@ -319,7 +338,7 @@ export default {
|
|
|
319
338
|
* {
|
|
320
339
|
* path: '/',
|
|
321
340
|
* route: {
|
|
322
|
-
* canonical: 'https://
|
|
341
|
+
* canonical: 'https://api.umami.demo.druxtjs.org/en/node',
|
|
323
342
|
* component: 'druxt-view',
|
|
324
343
|
* error: false,
|
|
325
344
|
* isHomePath: true,
|
|
@@ -334,7 +353,7 @@ export default {
|
|
|
334
353
|
*/
|
|
335
354
|
|
|
336
355
|
/**
|
|
337
|
-
* Provides scoped slots for use in the
|
|
356
|
+
* Provides scoped slots for use in the wrapper component.
|
|
338
357
|
*
|
|
339
358
|
* @typedef {object} ScopedSlots
|
|
340
359
|
* @param {function} debug - A Debug component with a Path override field.
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* @type {object}
|
|
5
5
|
* @exports DruxtRouterComponent
|
|
6
6
|
* @name DruxtRouterComponent
|
|
7
|
-
* @see {@link ./
|
|
7
|
+
* @see {@link ./DruxtRouter|DruxtRouterComponent}
|
|
8
8
|
*
|
|
9
|
-
* @example
|
|
9
|
+
* @example @lang js
|
|
10
10
|
* <script>
|
|
11
11
|
* import { DruxtRouterComponent } from 'druxt-router/dist/components'
|
|
12
12
|
*
|
package/dist/druxt-router.esm.js
CHANGED
|
@@ -34,7 +34,7 @@ class DruxtRouter {
|
|
|
34
34
|
],
|
|
35
35
|
...options
|
|
36
36
|
};
|
|
37
|
-
this.druxt = new DruxtClient(baseUrl, this.options);
|
|
37
|
+
this.druxt = options.druxtClient || new DruxtClient(baseUrl, this.options);
|
|
38
38
|
this.axios = this.druxt.axios;
|
|
39
39
|
}
|
|
40
40
|
addHeaders(headers) {
|
|
@@ -70,7 +70,7 @@ class DruxtRouter {
|
|
|
70
70
|
const url = Url(path);
|
|
71
71
|
if (route.isHomePath) {
|
|
72
72
|
const homePath = prefix ? `/${prefix}` : "/";
|
|
73
|
-
if (!
|
|
73
|
+
if (!["/", homePath, `${homePath}/`].includes(url.pathname)) {
|
|
74
74
|
return homePath;
|
|
75
75
|
}
|
|
76
76
|
return false;
|
|
@@ -183,7 +183,7 @@ const DruxtRouterStore = ({ store }) => {
|
|
|
183
183
|
}),
|
|
184
184
|
mutations: {
|
|
185
185
|
addEntity(state, entity) {
|
|
186
|
-
console.warn("[druxt-router] `druxtRouter/addEntity` is deprecated. See
|
|
186
|
+
console.warn("[druxt-router] `druxtRouter/addEntity` is deprecated. See https://druxtjs.org/api/packages/druxt/stores/druxt");
|
|
187
187
|
if (!entity || typeof entity.id === "undefined") {
|
|
188
188
|
return;
|
|
189
189
|
}
|
|
@@ -208,8 +208,8 @@ const DruxtRouterStore = ({ store }) => {
|
|
|
208
208
|
actions: {
|
|
209
209
|
async get({ commit, dispatch }, path) {
|
|
210
210
|
const route = await dispatch("getRoute", path);
|
|
211
|
-
if (route.error && typeof route.error.statusCode !== "undefined"
|
|
212
|
-
return
|
|
211
|
+
if (route.error && typeof route.error.statusCode !== "undefined") {
|
|
212
|
+
return { error: route.error, route };
|
|
213
213
|
}
|
|
214
214
|
commit("setRoute", path);
|
|
215
215
|
const redirect = this.$druxtRouter().getRedirect(path, route);
|
|
@@ -217,7 +217,7 @@ const DruxtRouterStore = ({ store }) => {
|
|
|
217
217
|
return { redirect, route };
|
|
218
218
|
},
|
|
219
219
|
async getEntity({ commit, state }, query) {
|
|
220
|
-
console.warn("[druxt-router] `druxtRouter/getEntity` is deprecated. See
|
|
220
|
+
console.warn("[druxt-router] `druxtRouter/getEntity` is deprecated. See https://druxtjs.org/api/packages/druxt/stores/druxt");
|
|
221
221
|
if (typeof state.entities[query.id] !== "undefined") {
|
|
222
222
|
return state.entities[query.id];
|
|
223
223
|
}
|
|
@@ -226,7 +226,7 @@ const DruxtRouterStore = ({ store }) => {
|
|
|
226
226
|
return entity.data;
|
|
227
227
|
},
|
|
228
228
|
async getResources(app, { resource, query }) {
|
|
229
|
-
console.warn("[druxt-router] `druxtRouter/getResources` is deprecated. See
|
|
229
|
+
console.warn("[druxt-router] `druxtRouter/getResources` is deprecated. See https://druxtjs.org/api/packages/druxt/stores/druxt");
|
|
230
230
|
const collection = await this.app.store.dispatch("druxt/getCollection", { type: resource, query });
|
|
231
231
|
return collection.data || false;
|
|
232
232
|
},
|
|
@@ -238,7 +238,9 @@ const DruxtRouterStore = ({ store }) => {
|
|
|
238
238
|
try {
|
|
239
239
|
route = await this.$druxtRouter().getRoute(path);
|
|
240
240
|
} catch (err) {
|
|
241
|
-
|
|
241
|
+
const statusCode = (err.response || {}).status || 500;
|
|
242
|
+
const message = ((err.response || {}).data || {}).message || err.message;
|
|
243
|
+
route = { error: { statusCode, message } };
|
|
242
244
|
}
|
|
243
245
|
commit("addRoute", { path, route });
|
|
244
246
|
return route;
|
package/dist/druxt-router.ssr.js
CHANGED
|
@@ -43,7 +43,7 @@ class DruxtRouter {
|
|
|
43
43
|
],
|
|
44
44
|
...options
|
|
45
45
|
};
|
|
46
|
-
this.druxt = new druxt.DruxtClient(baseUrl, this.options);
|
|
46
|
+
this.druxt = options.druxtClient || new druxt.DruxtClient(baseUrl, this.options);
|
|
47
47
|
this.axios = this.druxt.axios;
|
|
48
48
|
}
|
|
49
49
|
addHeaders(headers) {
|
|
@@ -79,7 +79,7 @@ class DruxtRouter {
|
|
|
79
79
|
const url = Url__default["default"](path);
|
|
80
80
|
if (route.isHomePath) {
|
|
81
81
|
const homePath = prefix ? `/${prefix}` : "/";
|
|
82
|
-
if (!
|
|
82
|
+
if (!["/", homePath, `${homePath}/`].includes(url.pathname)) {
|
|
83
83
|
return homePath;
|
|
84
84
|
}
|
|
85
85
|
return false;
|
|
@@ -192,7 +192,7 @@ const DruxtRouterStore = ({ store }) => {
|
|
|
192
192
|
}),
|
|
193
193
|
mutations: {
|
|
194
194
|
addEntity(state, entity) {
|
|
195
|
-
console.warn("[druxt-router] `druxtRouter/addEntity` is deprecated. See
|
|
195
|
+
console.warn("[druxt-router] `druxtRouter/addEntity` is deprecated. See https://druxtjs.org/api/packages/druxt/stores/druxt");
|
|
196
196
|
if (!entity || typeof entity.id === "undefined") {
|
|
197
197
|
return;
|
|
198
198
|
}
|
|
@@ -217,8 +217,8 @@ const DruxtRouterStore = ({ store }) => {
|
|
|
217
217
|
actions: {
|
|
218
218
|
async get({ commit, dispatch }, path) {
|
|
219
219
|
const route = await dispatch("getRoute", path);
|
|
220
|
-
if (route.error && typeof route.error.statusCode !== "undefined"
|
|
221
|
-
return
|
|
220
|
+
if (route.error && typeof route.error.statusCode !== "undefined") {
|
|
221
|
+
return { error: route.error, route };
|
|
222
222
|
}
|
|
223
223
|
commit("setRoute", path);
|
|
224
224
|
const redirect = this.$druxtRouter().getRedirect(path, route);
|
|
@@ -226,7 +226,7 @@ const DruxtRouterStore = ({ store }) => {
|
|
|
226
226
|
return { redirect, route };
|
|
227
227
|
},
|
|
228
228
|
async getEntity({ commit, state }, query) {
|
|
229
|
-
console.warn("[druxt-router] `druxtRouter/getEntity` is deprecated. See
|
|
229
|
+
console.warn("[druxt-router] `druxtRouter/getEntity` is deprecated. See https://druxtjs.org/api/packages/druxt/stores/druxt");
|
|
230
230
|
if (typeof state.entities[query.id] !== "undefined") {
|
|
231
231
|
return state.entities[query.id];
|
|
232
232
|
}
|
|
@@ -235,7 +235,7 @@ const DruxtRouterStore = ({ store }) => {
|
|
|
235
235
|
return entity.data;
|
|
236
236
|
},
|
|
237
237
|
async getResources(app, { resource, query }) {
|
|
238
|
-
console.warn("[druxt-router] `druxtRouter/getResources` is deprecated. See
|
|
238
|
+
console.warn("[druxt-router] `druxtRouter/getResources` is deprecated. See https://druxtjs.org/api/packages/druxt/stores/druxt");
|
|
239
239
|
const collection = await this.app.store.dispatch("druxt/getCollection", { type: resource, query });
|
|
240
240
|
return collection.data || false;
|
|
241
241
|
},
|
|
@@ -247,7 +247,9 @@ const DruxtRouterStore = ({ store }) => {
|
|
|
247
247
|
try {
|
|
248
248
|
route = await this.$druxtRouter().getRoute(path);
|
|
249
249
|
} catch (err) {
|
|
250
|
-
|
|
250
|
+
const statusCode = (err.response || {}).status || 500;
|
|
251
|
+
const message = ((err.response || {}).data || {}).message || err.message;
|
|
252
|
+
route = { error: { statusCode, message } };
|
|
251
253
|
}
|
|
252
254
|
commit("addRoute", { path, route });
|
|
253
255
|
return route;
|
package/icon.svg
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
2
|
+
<circle stroke="#036397" cx="5.75" cy="18.25" r="2.25" />
|
|
3
|
+
<path stroke="#036397" d="M7.4 16.6c3.2-2.6 1.4-6.1 4.4-8.1 1.3-.87 2.5-.95 4.1-1.05" />
|
|
4
|
+
<circle stroke="#3b8070" cx="18.25" cy="5.75" r="2.25" />
|
|
5
|
+
</svg>
|
package/nuxt/index.d.ts
CHANGED
|
@@ -9,20 +9,30 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Options are set on the root level `druxt` Nuxt config object.
|
|
11
11
|
*
|
|
12
|
+
* A Nuxt module configures the Nuxt application, and is unrelated to a Drupal module.
|
|
13
|
+
*
|
|
14
|
+
* @see https://druxtjs.org/modules/router
|
|
15
|
+
* @see https://druxtjs.org/explanation/nuxt-for-drupal-developers
|
|
16
|
+
*
|
|
12
17
|
* @example @lang js
|
|
13
18
|
* // `nuxt.config.js`
|
|
14
19
|
* module.exports = {
|
|
15
20
|
* buildModules: ['druxt-router/nuxt'],
|
|
16
21
|
* druxt: {
|
|
17
|
-
* baseUrl: 'https://
|
|
22
|
+
* baseUrl: 'https://api.umami.demo.druxtjs.org'
|
|
18
23
|
* }
|
|
19
24
|
* }
|
|
20
25
|
*
|
|
26
|
+
* @param {object} moduleOptions - The Nuxt.js module options.
|
|
21
27
|
* @property {object} options.druxt - Druxt root level options.
|
|
22
|
-
* @property {string} options.druxt.baseUrl - Base URL of Drupal JSON:API backend.
|
|
23
|
-
* @property {string} options.druxt.
|
|
28
|
+
* @property {string} options.druxt.baseUrl - Base URL of the Drupal JSON:API backend.
|
|
29
|
+
* @property {string} [options.druxt.endpoint=/jsonapi] - The Drupal JSON:API endpoint path.
|
|
30
|
+
* @property {object} [options.druxt.axios] - Axios settings for the DruxtRouter client.
|
|
31
|
+
* @property {boolean} [options.druxt.proxy.api] - Proxy JSON:API requests on the client side.
|
|
32
|
+
* @property {string} [options.druxt.router.render] - Name of the component used to render the
|
|
33
|
+
* resolved route.
|
|
24
34
|
*/
|
|
25
|
-
declare function DruxtRouterNuxtModule(moduleOptions?:
|
|
35
|
+
declare function DruxtRouterNuxtModule(moduleOptions?: object): Promise<void>;
|
|
26
36
|
declare namespace DruxtRouterNuxtModule {
|
|
27
37
|
const meta: any;
|
|
28
38
|
}
|
package/nuxt/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const path = require('path');
|
|
|
7
7
|
const drupalJsonapiParams = require('drupal-jsonapi-params');
|
|
8
8
|
const druxt = require('druxt');
|
|
9
9
|
|
|
10
|
+
const extendComponent = (component) => ({ ...component, isAsync: false });
|
|
10
11
|
const DruxtRouterNuxtModule = async function(moduleOptions = {}) {
|
|
11
12
|
const options = {
|
|
12
13
|
baseUrl: moduleOptions.baseUrl,
|
|
@@ -20,7 +21,7 @@ const DruxtRouterNuxtModule = async function(moduleOptions = {}) {
|
|
|
20
21
|
};
|
|
21
22
|
await this.addModule(["druxt", options]);
|
|
22
23
|
this.nuxt.hook("components:dirs", (dirs) => {
|
|
23
|
-
dirs.push({ path: path.join(__dirname, "../dist/components") });
|
|
24
|
+
dirs.push({ path: path.join(__dirname, "../dist/components"), extendComponent });
|
|
24
25
|
});
|
|
25
26
|
if (options.router.wildcard) {
|
|
26
27
|
if (!options.router.pages) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "druxt-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.1-dev.20260920043715",
|
|
4
4
|
"description": "Drupal router for Nuxt, powered by the Drupal Decoupled Router module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"url": "git+https://github.com/druxt/druxt.js"
|
|
27
27
|
},
|
|
28
28
|
"license": "MIT",
|
|
29
|
+
"author": "Stuart Clark <stuart@druxtjs.org>",
|
|
29
30
|
"exports": {
|
|
30
31
|
".": {
|
|
31
32
|
"require": "./dist/druxt-router.ssr.js",
|
|
@@ -39,20 +40,23 @@
|
|
|
39
40
|
"files": [
|
|
40
41
|
"dist",
|
|
41
42
|
"nuxt",
|
|
42
|
-
"templates"
|
|
43
|
+
"templates",
|
|
44
|
+
"icon.svg",
|
|
45
|
+
"banner.svg"
|
|
43
46
|
],
|
|
44
47
|
"dependencies": {
|
|
45
|
-
"druxt": "
|
|
48
|
+
"druxt": "0.24.1-dev.20260920043715",
|
|
46
49
|
"url-parse": "^1.5.10"
|
|
47
50
|
},
|
|
48
51
|
"devDependencies": {
|
|
52
|
+
"axios": "0.33.0",
|
|
49
53
|
"vue-router": "^3.6.5"
|
|
50
54
|
},
|
|
51
55
|
"peerDependencies": {
|
|
52
56
|
"drupal-jsonapi-params": "*"
|
|
53
57
|
},
|
|
54
58
|
"optionalDependencies": {
|
|
55
|
-
"vue": "^2.7.
|
|
59
|
+
"vue": "^2.7.16",
|
|
56
60
|
"vuex": "^3.6.2"
|
|
57
61
|
},
|
|
58
62
|
"publishConfig": {
|
package/templates/plugin.js
CHANGED
|
@@ -29,6 +29,11 @@ export default ({ app }, inject) => {
|
|
|
29
29
|
options.axios = app.$axios
|
|
30
30
|
<% } %>
|
|
31
31
|
|
|
32
|
+
// Reuse the druxt module client if available.
|
|
33
|
+
if (app.$druxt) {
|
|
34
|
+
options.druxtClient = app.$druxt
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
const router = new DruxtRouter(baseUrl, options)
|
|
33
38
|
inject('druxtRouter', () => router)
|
|
34
39
|
}
|