From: Ardis Lu Date: Fri, 11 Aug 2023 04:21:36 +0000 (-0700) Subject: Add note and demo about scroll reset on navigation X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=291eeeca16d8da504fd7460558d7d2e59d2cdbd9;p=minimal-routing Add note and demo about scroll reset on navigation --- diff --git a/index.html b/index.html index c49040c..ff63154 100644 --- a/index.html +++ b/index.html @@ -84,7 +84,11 @@ p.subtitle { font-weight: 700; } - + + div.force-scroll { + block-size: 200vh; + } + @media (max-width: 800px) { main { grid-template: @@ -145,11 +149,24 @@
  • Middle click, Ctrl / Cmd click, Shift click, and "right click > open link in new tab" all need to work on links and link-like buttons as expected.
  • Invalid routes need to return HTTP 404 errors (this behavior is critical for SEO).
  • When hovering links and link-like buttons, the web browser's native status bar (typically shown at the bottom-left of the window) needs to show the destination address.
  • +
  • When navigating between long pages with scrollbars, the scroll should reset to the top of the page. Click here to see a demo.
  • The purpose of this website is to isolate the problem of client-side routing and provide a minimal reference implementation for it.

    All the behaviors above have been implemented for this website in about 50 total lines of JavaScript.

    Click here to view the source code on GitHub.

    +
    +

    This page is intentionally oversized. Scroll down to go to /long_page_2.

    +

    Or click here to go back to /page_3.

    +
    +

    Click here to go to /long_page_2.

    +
    +
    +

    The scroll should have been reset to the top when you entered this page.

    +

    Single-page apps that do not explicitly implement this behavior would have you enter this page with the scroll bar already scrolled down (to match your scroll on /long_page_1).

    +
    +

    Click here to go back to /long_page_1.

    +
    @@ -192,6 +209,8 @@ window.history.pushState({}, '', url); showPage(path); + // Must reset scroll otherwise a user entering a long page from another long page will enter midway scrolled + scroll(0, 0); } // Set event handlers