Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Prevent routing to current path #28

Closed
lukeed opened this issue Apr 12, 2020 · 4 comments
Closed

[RFC] Prevent routing to current path #28

lukeed opened this issue Apr 12, 2020 · 4 comments

Comments

@lukeed
Copy link
Owner

lukeed commented Apr 12, 2020

Assuming this setup:

router = (
  navaid()
    .on('/', () => console.log('doing something'))
    .listen()
);

You will be doing something every time the "/" path is routed. This is common sense & to be expected. However, what might not be obvious is that if you have a standard link in a global component (eg, a navbar) pointing to the home page:

<a href="/">Go Home</a>

... and click it repeatedly, you will be doing something for each of those clicks, even though you're already on the "/" route.


This is posted as a RFC because it might qualify as a breaking change in some apps.
Many might actually be relying on this behavior to reset page state, for example.

Please let me know below :)

@arxpoetica
Copy link

In SPAs, I would think not repeat the / action on 2nd+ clicks.

@lukeed
Copy link
Owner Author

lukeed commented Apr 13, 2020

Leaning towards @TehShrike's suggestion of allowing the route's handler(s) to rerun but preventing extra history.pushState stacks.

This maintains the ability of refreshing the page (if your App allows) by clicking the home/logo repeatedly. This could be prevented & disabled within App if that's undesired. By contrast, my initial suggestion required you to supply a dedicated "refresh" button and/or require users to hard-reload the page. That seems wrong.


The nice thing is that this adds only ~6 bytes and is not a breaking change.

@saibotsivad
Copy link
Sponsor

In a static site, if you click a link that navigates to the same page you are on, the browser still sends the HTTP request, allowing the server to send updated data, but the history stack does not change. (In Firefox 75.0 at least.)

To keep that user experience consistent, clicking repeatedly on a link to a page that you are already at should rerun the route handler(s) but not push to the history stack.

@lukeed
Copy link
Owner Author

lukeed commented Apr 13, 2020

Agreed :) You both have convinced me

@lukeed lukeed closed this as completed in e7d9aa5 Apr 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants