Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Replace Navigation History Items with Gatsby’s Link Component

    Jason LengstorfJason Lengstorf

    In some cases, navigating to a new page should replace the current page, meaning the “back” button will skip the current URL. For example, if a page leads to an interstitial screen, such as a confirmation page, it may be desirable to skip that confirmation if the user clicks the “back” button after confirming. In this video, you’ll learn how Gatsby’s Link component manages replacing navigation history using the replace prop.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    Instructor: In some cases, we don't want to keep every page that we visit in history. For example, if I choose waffles, I'm asked to confirm my choice. Once I confirm, I see what I've chosen. Then I'm told to press the back button to keep making decisions. If I hit back, I go back to this confirmation page, but what I really want is to be on the decision page.

    To fix that, we can use the replace prop in Gatsby's Link component. The way that that will happen is on the confirm page, where we have this Link prop, we can add replace. Adding the replace prop means that when we navigate to choice, instead of adding it as the next page we visited, it will replace the confirm page entirely in history.

    We can see how this works by going back out and choosing pancakes. Yes, I'm sure. Now, when we hit back, it goes straight to decisions. There aren't a lot of reasons why you would do this, but in the case of something like a confirmation page, it can make sense. It's helpful to know how it works.