4

So I originally created a website with smooth scroll whenever I click my nav menu items, but now I want my buttons to link to additional pages to display more info.

My issue is for my styled components, I had to import link from react scroll to ensure they work, but now this conflicts with my nav button that I am trying to link with react router

 import { Link } from 'react-scroll';
 import { Link } from 'react-router-dom';

I want my nav links to have react scroll

 export const NavLinks = styled(Link)``

But I want my button in the nav which is inside another div to use react-router

 export const NavBtnLink = styled(Link)``

Is that normal for websites to have smooth scroll and link to different pages? Or is smooth scroll meant only for one page static sites?

I don't get how I could have a signup button on a smooth scroll site if I can't link to a different page aka route

Code below

React Router not switching pages

React-scroll home nav link

           <NavLinks
              to='home'
              smooth={true}
              duration={500}
              spy={true}
              exact='true'
              offset={-80}
            >
              Home
            </NavLinks>

React-router nav btn

<NavBtnLink to='/signupa'>Sign In</NavBtnLink>

My App.js

  <Router>
  <Sidebar isOpen={isOpen} toggle={toggle} />
  <Navbar toggle={toggle} />
  <Home />
  <Switch>
    <Route path='/signupa' component={SignUpa} />
  </Switch>
  <Footer />
</Router>

My signup.js inside of my pages folder

    function SignUpa() {
      return (
        <>
          <h1>Signupa page</h1>
        </>
      );
    }

    export default SignUpa;

This is my home page that shows my entire site and the sections my react-scroll navigates to

    function Home() {
      return (
        <>
          <HeroSection />
          <InfoSection {...homeObjOne} />
          <InfoSection {...homeObjTwo} />
          <Services />
          <InfoSection {...homeObjThree} />
        </>
      );
    }

The HeroSection has the id="home" so it can scroll to that part, but I think that might be an issue now cause if I navigate to another page, idk how it will be able to take me back to the home page '/'

  <HeroContainer id='home'>

1 Answer 1

2

You can achieve this using alias name for import

import { Link as Link1 } from 'react-scroll';
import { Link as Link2 } from 'react-router-dom';

Then you can you accordingly the new alias name where you need!

Sign up to request clarification or add additional context in comments.

9 Comments

so I added that alias, but when I try to click on my button it just updates the URL, but the actual page does nothing
I tried to add some, but not sure if that helps or if you need more details. Also, I already had a nav menu item called signup, so I just had to change my new page to signupa so it doesn't conflict with path names
Did you added the route to Switch? Which is not rendering anything?
` <Switch> <Route path='/signupa' component={SignUpa} /> </Switch>` I did this to test the component to see if something changes,but it didn't do anything
For to="home", can you try adding "/home" and where did you configured to display the Home on this route?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.