1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2025-02-02 04:17:55 +01:00

Fixed instant navigation anchor scoll restoration issue

This commit is contained in:
squidfunk 2025-01-21 11:37:20 +07:00
parent c6fd95611d
commit 07a434b465
No known key found for this signature in database
GPG Key ID: 5ED40BC4F9C436DF
4 changed files with 9 additions and 14 deletions

View File

@ -249,7 +249,7 @@
</script> </script>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script src="{{ 'assets/javascripts/bundle.60a45f97.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/bundle.5090c770.min.js' | url }}"></script>
{% for script in config.extra_javascript %} {% for script in config.extra_javascript %}
{{ script | script_tag }} {{ script | script_tag }}
{% endfor %} {% endfor %}

View File

@ -366,15 +366,10 @@ export function setupInstantNavigation(
// Handle instant navigation events that are triggered by the user clicking // Handle instant navigation events that are triggered by the user clicking
// on an anchor link with a hash fragment different from the current one, as // on an anchor link with a hash fragment different from the current one, as
// well as from popstate events, which are emitted when the user navigates // well as from popstate events, which are emitted when the user navigates
// back and forth between pages. We use a two-layered subscription to scope // back and forth between pages.
// the scroll restoration to the current page, as we don't need to restore
// the viewport offset when the user navigates to a different page, as this
// is already handled by the previous observable.
document$.pipe( document$.pipe(
switchMap(() => location$), switchMap(() => location$),
distinctUntilKeyChanged("pathname"), distinctUntilKeyChanged("hash"),
switchMap(() => location$),
distinctUntilKeyChanged("hash")
), ),
// Handle instant navigation events that are triggered by the user clicking // Handle instant navigation events that are triggered by the user clicking