Skip to content

Commit

Permalink
fix: anchor option didn't work for <Router />
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed Dec 10, 2024
1 parent ec88b51 commit 25bbb07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/runtime/Router/Router.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
router._claimed = true
const context = new RouterContext({ router })
router.context = context
context.anchorLocation = anchor
router.onMount.run({ context, router })
context.decorators = context.decorators.map(normalizeDecorator)
Expand Down
16 changes: 16 additions & 0 deletions lib/runtime/decorators/AnchorDecorator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,39 @@
}
const handlers = {
/**
* Wraps an anchor element around the node
*/
wrapper: elem => {
elem.dataset.routifyAnchorWrapper = name
onMount(elem)
},
/**
* Uses the parent element as the node's anchor
* Note that if multiple nodes use the same parent, they will share the same anchor
*/
parent: elem => {
elem.dataset.routifyAnchorParent = name
onMount(elem.parentElement)
},
/**
* Creates an anchor element before the node
*/
header: elem => {
elem.dataset.routifyAnchorHeader = name
onMount(elem.parentElement, elem)
},
/**
* Uses the first element of the node as the anchor
*/
firstChild: elem => {
const nextSib = nextValidSibling(elem)
nextSib.dataset.routifyAnchorNextSibling = name
onMount(elem.parentElement, nextSib)
},
/**
* Uses a custom function to determine the anchor
*/
custom: elem => {
// @ts-ignore location is a function
const res = location(elem)
Expand Down

0 comments on commit 25bbb07

Please sign in to comment.