Skip to content

Commit

Permalink
fix: scroll to hash
Browse files Browse the repository at this point in the history
closes #550
  • Loading branch information
jakobrosenberg committed Apr 7, 2024
1 parent d1decc0 commit 9d693d5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/runtime/Router/urlReflectors/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class AddressReflector extends BaseReflector {
this._popstateHandler = event =>
router.url.pop(
urlFromBrowser(router),
event.state.routify?.router[router.name],
event.state?.routify?.router[router.name],
)
}

Expand Down
7 changes: 3 additions & 4 deletions lib/runtime/plugins/scroller/ScrollContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ export class ScrollContext {

this.scrollTarget = anchor || parent

const hashElem =
ctx.route?.hash && globalThis.document?.getElementById(ctx.route?.hash)

const hash = ctx.route?.sourceUrl.hash.slice(1)
const hashElem = hash && globalThis.document?.getElementById(hash)
this.elem = hashElem || this.scrollTarget

this.shouldScrollToElem = ctx.isInline || ctx.route?.hash
this.shouldScrollToElem = ctx.isInline || hashElem

this.isInstant = ctx.route?.state.dontsmoothscroll || !ctx.wasVisible

Expand Down
2 changes: 1 addition & 1 deletion lib/runtime/plugins/scroller/ScrollDecorator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
isRoot
const routeHasHashAndWeAreAtTheLeaf = route =>
route.hash && route.leaf === context.fragment
route.sourceUrl.hash && route.leaf === context.fragment
const contextLineageIsActive = () =>
getLineage(context).every(ctx => get(ctx.isActive))
Expand Down

0 comments on commit 9d693d5

Please sign in to comment.