@nuxt/bridge-edge 3.0.0-27846691.4aaf4eb → 3.0.0-27851925.695ddd7

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.
@@ -1,7 +1,7 @@
1
1
  import { Ref } from 'vue';
2
2
  import type { MetaInfo } from 'vue-meta';
3
3
  import type VueRouter from 'vue-router';
4
- import type { Location, RawLocation, Route } from 'vue-router';
4
+ import type { Location, RawLocation, Route, NavigationFailure } from 'vue-router';
5
5
  import type { RuntimeConfig } from '@nuxt/schema';
6
6
  export { useLazyAsyncData, refreshNuxtData } from './asyncData';
7
7
  export { useLazyFetch } from './fetch';
@@ -25,8 +25,10 @@ export interface AddRouteMiddlewareOptions {
25
25
  }
26
26
  export interface NavigateToOptions {
27
27
  replace?: boolean;
28
+ redirectCode?: number;
29
+ external?: boolean;
28
30
  }
29
- export declare const navigateTo: (to: RawLocation, options?: NavigateToOptions) => Promise<RawLocation | Route | void> | RawLocation | Route;
31
+ export declare const navigateTo: (to: RawLocation | undefined | null, options?: NavigateToOptions) => Promise<void | Route | NavigationFailure> | RawLocation | Route;
30
32
  /** This will abort navigation within a Nuxt route middleware handler. */
31
33
  export declare const abortNavigation: (err?: Error | string) => boolean;
32
34
  type RouteMiddlewareReturn = void | Error | string | Location | boolean;
@@ -2,7 +2,7 @@ import { getCurrentInstance, onBeforeUnmount, isRef, watch, reactive, toRef, isR
2
2
  import { sendRedirect } from "h3";
3
3
  import { defu } from "defu";
4
4
  import { useRouter as useVueRouter, useRoute as useVueRoute } from "vue-router/composables";
5
- import { joinURL } from "ufo";
5
+ import { hasProtocol, joinURL, parseURL } from "ufo";
6
6
  import { useNuxtApp } from "./app.mjs";
7
7
  export { useLazyAsyncData, refreshNuxtData } from "./asyncData.mjs";
8
8
  export { useLazyFetch } from "./fetch.mjs";
@@ -142,17 +142,38 @@ const isProcessingMiddleware = () => {
142
142
  }
143
143
  return false;
144
144
  };
145
- export const navigateTo = (to, options = {}) => {
146
- if (isProcessingMiddleware()) {
145
+ export const navigateTo = (to, options) => {
146
+ if (!to) {
147
+ to = "/";
148
+ }
149
+ const toPath = typeof to === "string" ? to : to.path || "/";
150
+ const isExternal = hasProtocol(toPath, true);
151
+ if (isExternal && !options?.external) {
152
+ throw new Error("Navigating to external URL is not allowed by default. Use `nagivateTo (url, { external: true })`.");
153
+ }
154
+ if (isExternal && parseURL(toPath).protocol === "script:") {
155
+ throw new Error("Cannot navigate to an URL with script protocol.");
156
+ }
157
+ if (process.client && !isExternal && isProcessingMiddleware()) {
147
158
  return to;
148
159
  }
149
160
  const router = useRouter();
150
- if (process.server && useNuxtApp().ssrContext) {
151
- const event = useNuxtApp().ssrContext?.event;
152
- const redirectLocation = joinURL(useRuntimeConfig().app.baseURL, router.resolve(to).fullPath || "/");
153
- return sendRedirect(event, redirectLocation);
161
+ if (process.server) {
162
+ const nuxtApp = useNuxtApp();
163
+ if (nuxtApp.ssrContext && nuxtApp.ssrContext.event) {
164
+ const redirectLocation = isExternal ? toPath : joinURL(useRuntimeConfig().app.baseURL, router.resolve(to).fullPath || "/");
165
+ return nuxtApp.callHook("app:redirected").then(() => sendRedirect(nuxtApp.ssrContext.event, redirectLocation, options?.redirectCode || 302));
166
+ }
167
+ }
168
+ if (isExternal) {
169
+ if (options?.replace) {
170
+ location.replace(toPath);
171
+ } else {
172
+ location.href = toPath;
173
+ }
174
+ return Promise.resolve();
154
175
  }
155
- return options.replace ? router.replace(to) : router.push(to);
176
+ return options?.replace ? router.replace(to) : router.push(to);
156
177
  };
157
178
  export const abortNavigation = (err) => {
158
179
  if (process.dev && !isProcessingMiddleware()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/bridge-edge",
3
- "version": "3.0.0-27846691.4aaf4eb",
3
+ "version": "3.0.0-27851925.695ddd7",
4
4
  "repository": "nuxt/bridge",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
20
20
  "@babel/plugin-proposal-optional-chaining": "^7.18.9",
21
21
  "@babel/plugin-transform-typescript": "^7.20.2",
22
- "@nuxt/bridge-schema": "npm:@nuxt/bridge-schema-edge@3.0.0-27846691.4aaf4eb",
22
+ "@nuxt/bridge-schema": "npm:@nuxt/bridge-schema-edge@3.0.0-27851925.695ddd7",
23
23
  "@nuxt/devalue": "^2.0.0",
24
24
  "@nuxt/kit": "3.0.0",
25
25
  "@nuxt/postcss8": "^1.1.3",
@@ -37,8 +37,8 @@
37
37
  "externality": "^1.0.0",
38
38
  "fs-extra": "^10.1.0",
39
39
  "get-port-please": "^2.6.1",
40
- "globby": "^13.1.2",
41
- "h3": "^1.0.1",
40
+ "globby": "^13.1.3",
41
+ "h3": "^1.0.2",
42
42
  "hash-sum": "^2.0.0",
43
43
  "knitwork": "^1.0.0",
44
44
  "magic-string": "^0.27.0",
@@ -61,9 +61,9 @@
61
61
  "terser": "^5.16.1",
62
62
  "ufo": "^1.0.1",
63
63
  "unctx": "^2.1.1",
64
- "unimport": "^1.0.1",
65
- "unplugin": "^1.0.0",
66
- "untyped": "^1.0.0",
64
+ "unimport": "^1.0.2",
65
+ "unplugin": "^1.0.1",
66
+ "untyped": "^1.1.0",
67
67
  "vite": "~3.2.5",
68
68
  "vue-bundle-renderer": "^1.0.0"
69
69
  },
@@ -83,7 +83,7 @@
83
83
  "engines": {
84
84
  "node": "^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
85
85
  },
86
- "packageManager": "pnpm@7.18.1",
86
+ "packageManager": "pnpm@7.18.2",
87
87
  "_name": "@nuxt/bridge",
88
88
  "scripts": {
89
89
  "build": "pnpm prepack"