question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Navigating from another page

See original GitHub issue

Is it possible to navigate from another page? (using react Router v5 with create-react-app)

For example i have this exmple that is working on the HomePage. But if i click the navbar item from another page it doesn’t work.

How i navigate to anchor from another page?

import { Element} from 'react-scroll';

export function HomePage() {
    return (
        <>
                <title>Home</title>
                <Banner />

                <Element name="price-plan-list">
                    <PriceplanList />
                </Element>

                <Element name="entertainment-area">
                    <EntertainmentArea />
                </Element>
        </>
    );
}

And this is the NavbarItem:

import { Link as AnchorLink } from 'react-scroll';

        <NavItem key={index}>
            <AnchorLink
                activeClass="active"
                to={item.link}
                spy={true}
                smooth={'easeInOutCubic'}
                duration={1000}
                offset={-50}
            >
                {item.title}
            </AnchorLink>
        </NavItem>

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
ManWithA1000Namescommented, Feb 7, 2021

I do not know if this will help you guys, but what I did (in create-react-app and react-router-dom) is to use a scroller.scrollTo in a setTimeout, example:

<Link 
onClick={()=>{
 setTimeout(()=> {scroller.scrollTo("id", {smooth: true, duration: 15000}}, 750)
}} 
to="/otherPage"
>Go to specific part in other Page</Link> 

I have a page transition hence the 750 milliseconds, but i have tried as low a 1 and it still worked. This solution is kind of jank and I dont know if Search engine bots will like it.

3reactions
astridwallecommented, Dec 1, 2020

Hi, I’ve found the package react-scrollable-anchor https://www.npmjs.com/package/react-scrollable-anchor really helpful. This allows to navigate and scroll to a specific section even from another page, just by using href anchor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Navigate To Another Page In HTML - TalkersCode.com
In this tutorial we will show you the solution of how to navigate to another page in HTML and how you are able...
Read more >
Navigate to a new screen and back - Flutter documentation
Navigate to a new screen and back · 1. Create two routes · 2. Navigate to the second route using Navigator.push() · 3....
Read more >
How to navigate to other page in angular 6? - Stack Overflow
There more than two methods to navigate like navigate() , navigateByUrl() , and some other.. but we will mostly use these two. navigate()...
Read more >
Navigate Between Pages | Learn Next.js
Navigate Between Pages ... So far, the Next.js app we created only has one page. Websites and web applications generally have many different...
Read more >
How to navigate through my own page? When I click on 'About ...
A second option is to create your link as you normally would with your <a> tag and then style it via CSS: <a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found