Open React Router <Link> At The Top Of Page With JavaScript

Royer Adames
Aug 5, 2021

--

This solution uses JavaScript no through the React Router library. If you find a solution through the library please share it bellow.

You can do this by using a onClick anonymous function that calls the window to scroll to 0,0 coordinates.

Here is an example from one of my projects:

If you want to do a smooth scrolling this is how you do it:

Credit to asliwinski from stack overflow

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Royer Adames
Royer Adames

No responses yet

Write a response