@simonbackx/vue-app-navigation 2.4.1 → 2.4.2
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/dist/index.js +55 -26
- package/dist/src/utils/navigationHooks.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1817,6 +1817,44 @@ function getCurrentRoutes() {
|
|
|
1817
1817
|
function onCheckRoutes(handler) {
|
|
1818
1818
|
const instance = getCurrentInstance();
|
|
1819
1819
|
instance._navigationCheckRoutesHandlers = [...instance._navigationCheckRoutes ?? [], handler];
|
|
1820
|
+
addCheckRoutesMountedHandler();
|
|
1821
|
+
}
|
|
1822
|
+
function onNotCheckRoutes(handler) {
|
|
1823
|
+
const instance = getCurrentInstance();
|
|
1824
|
+
instance._navigationNotCheckRoutesHandlers = [...instance._navigationNotCheckRoutesHandlers ?? [], handler];
|
|
1825
|
+
addCheckRoutesMountedHandler();
|
|
1826
|
+
}
|
|
1827
|
+
function addCheckRoutesMountedHandler() {
|
|
1828
|
+
const instance = getCurrentInstance();
|
|
1829
|
+
const component = useCurrentComponent();
|
|
1830
|
+
if (instance._didAddCheckRoutesMountedHandler) {
|
|
1831
|
+
return;
|
|
1832
|
+
}
|
|
1833
|
+
instance._didAddCheckRoutesMountedHandler = true;
|
|
1834
|
+
onMounted(async () => {
|
|
1835
|
+
if (component && component.checkRoutes) {
|
|
1836
|
+
component.checkRoutes = false;
|
|
1837
|
+
if ("_navigationCheckRoutesHandlers" in instance && Array.isArray(instance._navigationCheckRoutesHandlers)) {
|
|
1838
|
+
for (const handler of instance._navigationCheckRoutesHandlers) {
|
|
1839
|
+
if (typeof handler === "function") {
|
|
1840
|
+
await handler();
|
|
1841
|
+
} else {
|
|
1842
|
+
console.error("Invalid checkRoutes handler", handler);
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
} else {
|
|
1847
|
+
if ("_navigationNotCheckRoutesHandlers" in instance && Array.isArray(instance._navigationNotCheckRoutesHandlers)) {
|
|
1848
|
+
for (const handler of instance._navigationNotCheckRoutesHandlers) {
|
|
1849
|
+
if (typeof handler === "function") {
|
|
1850
|
+
await handler();
|
|
1851
|
+
} else {
|
|
1852
|
+
console.error("Invalid not checkRoutes handler", handler);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
});
|
|
1820
1858
|
}
|
|
1821
1859
|
function defineRoutes(routes) {
|
|
1822
1860
|
const component = useCurrentComponent();
|
|
@@ -1887,42 +1925,32 @@ function defineRoutes(routes) {
|
|
|
1887
1925
|
}
|
|
1888
1926
|
}
|
|
1889
1927
|
};
|
|
1890
|
-
|
|
1891
|
-
if (
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
if (typeof handler === "function") {
|
|
1896
|
-
await handler();
|
|
1897
|
-
} else {
|
|
1898
|
-
console.error("Invalid checkRoutes handler", handler);
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1928
|
+
onCheckRoutes(async () => {
|
|
1929
|
+
if (Array.isArray(routes)) {
|
|
1930
|
+
if (await handleRoutes(routes)) {
|
|
1931
|
+
setDefaultHandler();
|
|
1932
|
+
return;
|
|
1901
1933
|
}
|
|
1902
|
-
|
|
1903
|
-
|
|
1934
|
+
} else {
|
|
1935
|
+
const extraRoutes = await routes();
|
|
1936
|
+
if (Array.isArray(extraRoutes)) {
|
|
1937
|
+
if (await handleRoutes(extraRoutes)) {
|
|
1904
1938
|
setDefaultHandler();
|
|
1905
1939
|
return;
|
|
1906
1940
|
}
|
|
1907
1941
|
} else {
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
setDefaultHandler();
|
|
1912
|
-
return;
|
|
1913
|
-
}
|
|
1914
|
-
} else {
|
|
1915
|
-
if (extraRoutes) {
|
|
1916
|
-
setDefaultHandler();
|
|
1917
|
-
return;
|
|
1918
|
-
}
|
|
1942
|
+
if (extraRoutes) {
|
|
1943
|
+
setDefaultHandler();
|
|
1944
|
+
return;
|
|
1919
1945
|
}
|
|
1920
1946
|
}
|
|
1921
|
-
} else {
|
|
1922
|
-
await defaultHandler({ allowDetail: false });
|
|
1923
1947
|
}
|
|
1924
1948
|
setDefaultHandler();
|
|
1925
1949
|
});
|
|
1950
|
+
onNotCheckRoutes(async () => {
|
|
1951
|
+
await defaultHandler({ allowDetail: false });
|
|
1952
|
+
setDefaultHandler();
|
|
1953
|
+
});
|
|
1926
1954
|
}
|
|
1927
1955
|
const checkRouteCache = {
|
|
1928
1956
|
lastUrl: null,
|
|
@@ -2915,6 +2943,7 @@ export {
|
|
|
2915
2943
|
matchQuery,
|
|
2916
2944
|
normalizePushOptions,
|
|
2917
2945
|
onCheckRoutes,
|
|
2946
|
+
onNotCheckRoutes,
|
|
2918
2947
|
setTitle,
|
|
2919
2948
|
setTitleSuffix,
|
|
2920
2949
|
templateToUrl,
|
|
@@ -68,6 +68,7 @@ export declare function useNavigate(): <Params extends Record<string, unknown>>(
|
|
|
68
68
|
export type DefaultRouteHandler = () => Promise<boolean>;
|
|
69
69
|
export type OnCheckRoutesHandler = () => Promise<void> | void;
|
|
70
70
|
export declare function onCheckRoutes(handler: OnCheckRoutesHandler): void;
|
|
71
|
+
export declare function onNotCheckRoutes(handler: OnCheckRoutesHandler): void;
|
|
71
72
|
export declare function defineRoutes(routes: (Route<any, undefined>[]) | (() => Promise<boolean | (Route<any, undefined>[])>)): void;
|
|
72
73
|
export declare function useCurrentHref(): Ref<string>;
|
|
73
74
|
export declare function useCheckRoute(): <Params extends Record<string, unknown>>(prop1: string | Route<Params, unknown>, prop2?: RouteNavigationOptions<Params>) => boolean;
|