You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is my use case. I have an application containing two parts:
1- The home page is divided into different sections with some hash-links for each section, something like this:
...
And I added these URLs using Link component from @tanStack/react-router package like below to my app navigation menu component:
<Link to="/" hash="about" activeOptions={{ includeHash: true }}>
About
</Link>
2- A dedicated page for contact-us with URL /contact and I added that to my navigation like below:
<Link to="/contact">Contact Us</Link>
Now to improve UX I wanna add two features to my app. First of all, I need smooth scrolling like the below:
1- When the current page is / and a user clicks on any link with hash-link in the menu I want to scroll to that section smoothly without jumping.
2- When the current page is /contact and for example, a user clicks on a /#about link. I want to first navigate to the home page (/) and then scroll to the about section.
To achieve this feature as I searched I have to use a package like react-scroll this package also has a Link component but I'm not sure how I can use this Link component with Link component from @tanStack/react-router together at the same time. I know I can use an alias in my import command but it's still not clear should I add Link component from react-scroll as a child of my router link or as a parent?
The second improvement I want to apply is for link spy and again supported by react-scroll so I think I can achieve that if I can solve the first problem.
Anyone here has any idea or experience to implement something like this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi guys,
This is my use case. I have an application containing two parts:
1- The home page is divided into different sections with some hash-links for each section, something like this:
The URLs for this page are something like this:
/
for Home/#about
for the about sectionAnd I added these URLs using
Link
component from@tanStack/react-router
package like below to my app navigation menu component:2- A dedicated page for
contact-us
with URL/contact
and I added that to my navigation like below:Now to improve UX I wanna add two features to my app. First of all, I need smooth scrolling like the below:
1- When the current page is
/
and a user clicks on any link with hash-link in the menu I want to scroll to that section smoothly without jumping.2- When the current page is
/contact
and for example, a user clicks on a/#about
link. I want to first navigate to the home page (/
) and then scroll to theabout
section.To achieve this feature as I searched I have to use a package like react-scroll this package also has a
Link
component but I'm not sure how I can use thisLink
component withLink
component from@tanStack/react-router
together at the same time. I know I can use an alias in my import command but it's still not clear should I addLink
component fromreact-scroll
as a child of my router link or as a parent?The second improvement I want to apply is for
link
spy and again supported byreact-scroll
so I think I can achieve that if I can solve the first problem.Anyone here has any idea or experience to implement something like this?
Beta Was this translation helpful? Give feedback.
All reactions