From b8496d532c754549b7333b34a2b2b86e65f762f7 Mon Sep 17 00:00:00 2001 From: Michiel van der Geest Date: Mon, 19 Feb 2024 15:16:49 +0100 Subject: [PATCH] Added functionality to pass data while navigating, which is injected as a prop - breaking change on the router.to() method. --- src/router/router.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/router/router.js b/src/router/router.js index 62413faa..75a2ed25 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -28,7 +28,9 @@ export let navigating = false const cacheMap = new WeakMap() const history = [] + let overrideOptions = {} +let navigationData = {} let navigatingBack = false let previousFocus @@ -133,7 +135,8 @@ export const navigate = async function () { holder.set('w', '100%') holder.set('h', '100%') // merge props with potential route params to be injected into the component instance - const props = { ...this[symbols.props], ...route.params } + const props = { ...this[symbols.props], ...route.params, ...navigationData } + view = await route.component({ props }, holder, this) if (view[Symbol.toStringTag] === 'Module') { if (view.default && typeof view.default === 'function') { @@ -250,7 +253,8 @@ const setOrAnimate = (node, transition, shouldAnimate = true) => { : node.set(transition.prop, transition.value) } -export const to = (location, options = {}) => { +export const to = (location, data = {}, options = {}) => { + navigationData = data overrideOptions = options window.location.hash = `#${location}` }