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

Add component to treat anchors as client side navigation #169

Merged
merged 3 commits into from
Apr 3, 2023

Conversation

tom-sherman
Copy link
Contributor

Adds a <TreatAnchorsAsClientSideNavigation> component that treats all <a> descendants with internal hrefs as if they were <Link> elements.

This allows you to opt into this behaviour scoped to just a portion of your app.

ref.current?.addEventListener(
"click",
(event) => {
const target = (event.target as Partial<HTMLElement>).closest?.("a");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Browser support for closest is pretty good but not perfect. Is it ok to use or should I replace with a manual parent search?

https://caniuse.com/element-closest

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compared it to ESM support it has a better support, so it should work on any Remix app.

@sergiodxa sergiodxa added the enhancement New feature or request label Apr 3, 2023
@sergiodxa sergiodxa merged commit 5a6856a into sergiodxa:main Apr 3, 2023
@tom-sherman tom-sherman deleted the client-navigation-links branch April 3, 2023 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants