diff --git a/lib/runtime/Router/Router.svelte b/lib/runtime/Router/Router.svelte index c1d4cc3f..b18dca37 100644 --- a/lib/runtime/Router/Router.svelte +++ b/lib/runtime/Router/Router.svelte @@ -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) diff --git a/lib/runtime/decorators/AnchorDecorator.svelte b/lib/runtime/decorators/AnchorDecorator.svelte index 16fff313..a0817bee 100644 --- a/lib/runtime/decorators/AnchorDecorator.svelte +++ b/lib/runtime/decorators/AnchorDecorator.svelte @@ -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)