@tanstack/vue-router 1.157.4 → 1.157.6
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,5 +1,6 @@
|
|
|
1
1
|
import { useStore } from "@tanstack/vue-store";
|
|
2
2
|
import * as Vue from "vue";
|
|
3
|
+
import { isServer } from "@tanstack/router-core/isServer";
|
|
3
4
|
import { useRouter } from "./useRouter.js";
|
|
4
5
|
function useRouterState(opts) {
|
|
5
6
|
const contextRouter = useRouter({
|
|
@@ -9,6 +10,11 @@ function useRouterState(opts) {
|
|
|
9
10
|
if (!router || !router.__store) {
|
|
10
11
|
return Vue.ref(void 0);
|
|
11
12
|
}
|
|
13
|
+
const _isServer = isServer ?? router.isServer;
|
|
14
|
+
if (_isServer) {
|
|
15
|
+
const state = router.state;
|
|
16
|
+
return Vue.ref(opts?.select ? opts.select(state) : state);
|
|
17
|
+
}
|
|
12
18
|
return useStore(router.__store, (state) => {
|
|
13
19
|
if (opts?.select) return opts.select(state);
|
|
14
20
|
return state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouterState.js","sources":["../../src/useRouterState.tsx"],"sourcesContent":["import { useStore } from '@tanstack/vue-store'\nimport * as Vue from 'vue'\nimport { useRouter } from './useRouter'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterState,\n} from '@tanstack/router-core'\n\nexport type UseRouterStateOptions<TRouter extends AnyRouter, TSelected> = {\n router?: TRouter\n select?: (state: RouterState<TRouter['routeTree']>) => TSelected\n}\n\nexport type UseRouterStateResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected ? RouterState<TRouter['routeTree']> : TSelected\n\nexport function useRouterState<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n>(\n opts?: UseRouterStateOptions<TRouter, TSelected>,\n): Vue.Ref<UseRouterStateResult<TRouter, TSelected>> {\n const contextRouter = useRouter<TRouter>({\n warn: opts?.router === undefined,\n })\n const router = opts?.router || contextRouter\n\n // Return a safe default if router is undefined\n if (!router || !router.__store) {\n return Vue.ref(undefined) as Vue.Ref<\n UseRouterStateResult<TRouter, TSelected>\n >\n }\n\n return useStore(router.__store, (state) => {\n if (opts?.select) return opts.select(state)\n\n return state\n }) as Vue.Ref<UseRouterStateResult<TRouter, TSelected>>\n}\n"],"names":["useRouterState","opts","contextRouter","useRouter","warn","router","undefined","__store","Vue","ref","
|
|
1
|
+
{"version":3,"file":"useRouterState.js","sources":["../../src/useRouterState.tsx"],"sourcesContent":["import { useStore } from '@tanstack/vue-store'\nimport * as Vue from 'vue'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterState,\n} from '@tanstack/router-core'\n\nexport type UseRouterStateOptions<TRouter extends AnyRouter, TSelected> = {\n router?: TRouter\n select?: (state: RouterState<TRouter['routeTree']>) => TSelected\n}\n\nexport type UseRouterStateResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected ? RouterState<TRouter['routeTree']> : TSelected\n\nexport function useRouterState<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n>(\n opts?: UseRouterStateOptions<TRouter, TSelected>,\n): Vue.Ref<UseRouterStateResult<TRouter, TSelected>> {\n const contextRouter = useRouter<TRouter>({\n warn: opts?.router === undefined,\n })\n const router = opts?.router || contextRouter\n\n // Return a safe default if router is undefined\n if (!router || !router.__store) {\n return Vue.ref(undefined) as Vue.Ref<\n UseRouterStateResult<TRouter, TSelected>\n >\n }\n\n // During SSR we render exactly once and do not need reactivity.\n // Avoid subscribing to the store on the server since the server store\n // implementation does not provide subscribe() semantics.\n const _isServer = isServer ?? router.isServer\n\n if (_isServer) {\n const state = router.state as RouterState<TRouter['routeTree']>\n return Vue.ref(opts?.select ? opts.select(state) : state) as Vue.Ref<\n UseRouterStateResult<TRouter, TSelected>\n >\n }\n\n return useStore(router.__store, (state) => {\n if (opts?.select) return opts.select(state)\n\n return state\n }) as Vue.Ref<UseRouterStateResult<TRouter, TSelected>>\n}\n"],"names":["useRouterState","opts","contextRouter","useRouter","warn","router","undefined","__store","Vue","ref","_isServer","isServer","state","select","useStore"],"mappings":";;;;AAoBO,SAASA,eAIdC,MACmD;AACnD,QAAMC,gBAAgBC,UAAmB;AAAA,IACvCC,MAAMH,MAAMI,WAAWC;AAAAA,EACzB,CAAC;AACD,QAAMD,SAASJ,MAAMI,UAAUH;AAG/B,MAAI,CAACG,UAAU,CAACA,OAAOE,SAAS;AAC9B,WAAOC,IAAIC,IAAIH,MAAS;AAAA,EAG1B;AAKA,QAAMI,YAAYC,YAAYN,OAAOM;AAErC,MAAID,WAAW;AACb,UAAME,QAAQP,OAAOO;AACrB,WAAOJ,IAAIC,IAAIR,MAAMY,SAASZ,KAAKY,OAAOD,KAAK,IAAIA,KAAK;AAAA,EAG1D;AAEA,SAAOE,SAAST,OAAOE,SAAUK,WAAU;AACzC,QAAIX,MAAMY,OAAQ,QAAOZ,KAAKY,OAAOD,KAAK;AAE1C,WAAOA;AAAAA,EACT,CAAC;AACH;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useStore } from '@tanstack/vue-store';
|
|
2
2
|
import * as Vue from 'vue';
|
|
3
|
+
import { isServer } from '@tanstack/router-core/isServer';
|
|
3
4
|
import { useRouter } from './useRouter';
|
|
4
5
|
export function useRouterState(opts) {
|
|
5
6
|
const contextRouter = useRouter({
|
|
@@ -10,6 +11,14 @@ export function useRouterState(opts) {
|
|
|
10
11
|
if (!router || !router.__store) {
|
|
11
12
|
return Vue.ref(undefined);
|
|
12
13
|
}
|
|
14
|
+
// During SSR we render exactly once and do not need reactivity.
|
|
15
|
+
// Avoid subscribing to the store on the server since the server store
|
|
16
|
+
// implementation does not provide subscribe() semantics.
|
|
17
|
+
const _isServer = isServer ?? router.isServer;
|
|
18
|
+
if (_isServer) {
|
|
19
|
+
const state = router.state;
|
|
20
|
+
return Vue.ref(opts?.select ? opts.select(state) : state);
|
|
21
|
+
}
|
|
13
22
|
return useStore(router.__store, (state) => {
|
|
14
23
|
if (opts?.select)
|
|
15
24
|
return opts.select(state);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouterState.jsx","sourceRoot":"","sources":["../../src/useRouterState.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAiBvC,MAAM,UAAU,cAAc,CAI5B,IAAgD;IAEhD,MAAM,aAAa,GAAG,SAAS,CAAU;QACvC,IAAI,EAAE,IAAI,EAAE,MAAM,KAAK,SAAS;KACjC,CAAC,CAAA;IACF,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,aAAa,CAAA;IAE5C,+CAA+C;IAC/C,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,GAAG,CAAC,SAAS,CAEvB,CAAA;IACH,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QACxC,IAAI,IAAI,EAAE,MAAM;YAAE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAE3C,OAAO,KAAK,CAAA;IACd,CAAC,CAAsD,CAAA;AACzD,CAAC"}
|
|
1
|
+
{"version":3,"file":"useRouterState.jsx","sourceRoot":"","sources":["../../src/useRouterState.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAiBvC,MAAM,UAAU,cAAc,CAI5B,IAAgD;IAEhD,MAAM,aAAa,GAAG,SAAS,CAAU;QACvC,IAAI,EAAE,IAAI,EAAE,MAAM,KAAK,SAAS;KACjC,CAAC,CAAA;IACF,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,aAAa,CAAA;IAE5C,+CAA+C;IAC/C,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,GAAG,CAAC,SAAS,CAEvB,CAAA;IACH,CAAC;IAED,gEAAgE;IAChE,sEAAsE;IACtE,yDAAyD;IACzD,MAAM,SAAS,GAAG,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAA;IAE7C,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,KAAK,GAAG,MAAM,CAAC,KAA0C,CAAA;QAC/D,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAEvD,CAAA;IACH,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QACxC,IAAI,IAAI,EAAE,MAAM;YAAE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAE3C,OAAO,KAAK,CAAA;IACd,CAAC,CAAsD,CAAA;AACzD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-router",
|
|
3
|
-
"version": "1.157.
|
|
3
|
+
"version": "1.157.6",
|
|
4
4
|
"description": "Modern and scalable routing for Vue applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"tiny-invariant": "^1.3.3",
|
|
65
65
|
"tiny-warning": "^1.0.3",
|
|
66
66
|
"@tanstack/history": "1.154.14",
|
|
67
|
-
"@tanstack/router-core": "1.157.
|
|
67
|
+
"@tanstack/router-core": "1.157.6"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@testing-library/jest-dom": "^6.6.3",
|
package/src/useRouterState.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useStore } from '@tanstack/vue-store'
|
|
2
2
|
import * as Vue from 'vue'
|
|
3
|
+
import { isServer } from '@tanstack/router-core/isServer'
|
|
3
4
|
import { useRouter } from './useRouter'
|
|
4
5
|
import type {
|
|
5
6
|
AnyRouter,
|
|
@@ -35,6 +36,18 @@ export function useRouterState<
|
|
|
35
36
|
>
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
// During SSR we render exactly once and do not need reactivity.
|
|
40
|
+
// Avoid subscribing to the store on the server since the server store
|
|
41
|
+
// implementation does not provide subscribe() semantics.
|
|
42
|
+
const _isServer = isServer ?? router.isServer
|
|
43
|
+
|
|
44
|
+
if (_isServer) {
|
|
45
|
+
const state = router.state as RouterState<TRouter['routeTree']>
|
|
46
|
+
return Vue.ref(opts?.select ? opts.select(state) : state) as Vue.Ref<
|
|
47
|
+
UseRouterStateResult<TRouter, TSelected>
|
|
48
|
+
>
|
|
49
|
+
}
|
|
50
|
+
|
|
38
51
|
return useStore(router.__store, (state) => {
|
|
39
52
|
if (opts?.select) return opts.select(state)
|
|
40
53
|
|