If you already have a subscription, you can sign in.
Enjoy free content straight from your inbox 💌
00:00
Since the next year's Link component does client side navigation, it supports the common pattern of an inplace navigation by overwriting the current entry in the browser history. Let's motivate this with a practical example. It is common for error pages to log some information to an error monitoring service, and within this simple app, we can see a demonstration of that within the console. Also, it is nice to give the user an opportunity to go back to a Happy Path workflow. In this example app, we are taking the user back to the homepage using the next link component. However, there is a concern with this navigation.
00:34
The user can actually click back to go back to the error page and cause another error, and we end up with a duplicate false error within our monitoring service. So it would be nice if you could navigate the user away from the error route, but don't leave a browser history for the error page, and this is quite easy to achieve. With the next year's link component, we simply add the replace prop providing the value true. If you've already gone through a React course, you would know that there is actually a shorthand for a prop that you want to assign to Drew. You simply provide the prop name, don't provide any value,
01:07
and it is automatically implied that prop equals true. Now, if you execute this code, go intentionally to the error page, you can see the error log on the console. If you choose to navigate to the homepage, the current history item will be replaced and we can actually verify that by looking at the history within the browser. There is no entry for the error page. There is only the fact that we started with the new tab, which is currently on the homepage.