Fixed anchor navigation when using instant loading

This commit is contained in:
squidfunk 2021-12-02 18:52:00 +01:00
parent b6ca0a1053
commit ebcd000fdc
4 changed files with 10 additions and 10 deletions

View File

@ -213,7 +213,7 @@
</script> </script>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script src="{{ 'assets/javascripts/bundle.e0abf5b0.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/bundle.33f85c42.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %} {% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script> <script src="{{ path | url }}"></script>
{% endfor %} {% endfor %}

View File

@ -326,13 +326,13 @@ export function setupInstantLoading(
/* Emit history state change */ /* Emit history state change */
merge(push$, pop$) merge(push$, pop$)
.pipe( .pipe(
sample(document$), sample(document$)
) )
.subscribe(({ url, offset = { y: 0 } }) => { .subscribe(({ url, offset }) => {
if (url.hash && !offset) { if (url.hash && !offset) {
setLocationHash(url.hash) setLocationHash(url.hash)
} else { } else {
window.scrollTo(0, offset.y) window.scrollTo(0, offset?.y || 0)
} }
}) })
@ -354,7 +354,7 @@ export function setupInstantLoading(
filter(([a, b]) => a.url.pathname === b.url.pathname), filter(([a, b]) => a.url.pathname === b.url.pathname),
map(([, state]) => state) map(([, state]) => state)
) )
.subscribe(({ offset = { y: 0 } }) => { .subscribe(({ offset }) => {
window.scrollTo(0, offset.y) window.scrollTo(0, offset?.y || 0)
}) })
} }