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

Make it work with react router v6 #92

Open
XzaR90 opened this issue Dec 4, 2021 · 12 comments
Open

Make it work with react router v6 #92

XzaR90 opened this issue Dec 4, 2021 · 12 comments

Comments

@XzaR90
Copy link

XzaR90 commented Dec 4, 2021

Hi, would be nice with a version for v6.

I made a fork but backwards compatibility is lost and at the moment custom link is gone.

@XzaR90
Copy link
Author

XzaR90 commented Dec 15, 2021

Added support for custom link as well but with breaking changes, GenericHashLink.
https://github.com/XzaR90/react-router-hash-link

@awreese
Copy link

awreese commented Dec 21, 2021

Does it need to be bumped all the way to React v17? RRDv6 still supports any version of React compatible with hooks, i.e. >=16.8.
https://github.com/remix-run/react-router/blob/main/packages/react-router-dom/package.json#L21

  "peerDependencies": {
    "react": ">=16.8",
    "react-dom": ">=16.8"
  },

@XzaR90
Copy link
Author

XzaR90 commented Dec 21, 2021

Oh, did not check. Well my fork is using typescript and I don,t know if you still want keep plain js. If you have any plan to migrate you can base it on my code if you find it okey and change the dependency as well.

@douglasrcjames
Copy link

Bumping this as an issue. Doing a bit of research on using anchor hash links with react-router-dom v6 and looks like they have no plan to implement this functionality into the library by default so
react-router-hash-link will be relevant and needs to be updated for v6!

@rafgraph
Copy link
Owner

rafgraph commented Feb 2, 2022

It's on my list, but it might be a little while before I get to it.

@ArthurBZhou
Copy link

The definition of NavLink.isActive has been changed in V6, please refer to
remix-run/react-router#7991 (comment)

@XzaR90
Copy link
Author

XzaR90 commented Feb 5, 2022

In my fork it can be used like this,

<NavHashLink
  to="/some/path#with-hash-fragment"
  className={(props) => {
    return `${props.isActive ? 'isActive ' : ''}`;
  }}
  style={(props) => {
    return props.isActive ? { fontWeight: 'bold' } : {};
  }}
  // etc...
>Link to Hash Fragment</NavHashLink>

@AyoCodess
Copy link

The scroll on this and the forked version does not work across all browsers on mobiles. Works fine on desktops. Any ideas?

@Peege151
Copy link

Peege151 commented Nov 19, 2022

Hey all. Working with React-Router V6, I define my routes like

<Route path='/account' element={<Account />} />, which I believe is causing a reload every time a hash link is clicked. #83 mentions that component={Account} would be the way to go, but I do not believe that is possible.

Currently the <HashLink> only works reliably if I set a timeout because the page is reloading even though it doesn't need to, it should be scrolling to the same page without a refresh.

@eduhsoto
Copy link

I use react router v6, so works well i use react router has link

@ncoughlin
Copy link

I've built a component that solves this problem passively in the background without having to modify any react-router Links.

GitHub: ScrollToHashElement

@santiaago
Copy link

thanks for sharing @ncoughlin ! worked like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants