Skip to content

Commit

Permalink
Merge pull request #61 from lightning-js/feature/router-pass-props-na…
Browse files Browse the repository at this point in the history
…vigating

Added functionality to pass data while navigating, which is injected …
  • Loading branch information
michielvandergeest authored Feb 20, 2024
2 parents 8f6f5c0 + b8496d5 commit b835914
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export let navigating = false

const cacheMap = new WeakMap()
const history = []

let overrideOptions = {}
let navigationData = {}
let navigatingBack = false
let previousFocus

Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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}`
}
Expand Down

0 comments on commit b835914

Please sign in to comment.