Course

URL State Management

Loading...

Have you noticed what happens when you visit any e-commerce website like Amazon and search for something?

Let’s try it now. Visit the Amazon website, and search for anything that you like. Maybe that MacBook you have been wanting to buy for a long time or that chocolate of yours? Search it

But while searching, keep an eye on “URL”.

Now search.

If you notice carefully enough, you’ll see whatever you typed in the search box will appear in the URL as is.

Amazon SS

If I share that URL with you here and if you open it. You should be able to see the same exact results.

This, my friend, is URL as a state management. You won’t see the same effect with other ways of state management.

Lots of websites, not just Amazon, use URLs as state management to keep track of stuff. Even Supabase does it.

For example, I wanted to check how many people bought our Ultimate Next.js course. So, I clicked on a filter, and the web address changed to show that filter.

https://supabase.com/dashboard/project/xxxxxxxxxxxxxxxxxxxx/editor/xxxxx?filter=course_name%3Aeq%3Aultimate-next-js-13-course-ebook&sort=created_at%3Adesc

You see, it's completely legal and actually considered a best practice. By managing state via the URL, you can easily share links, and when someone else opens that link, they'll see the same result as you did. This also helps improve SEO.

Insight

💡 How does URL as a state management improve SEO?

When you use unique URLs to represent different states or pages within your website, each URL serves as a distinct entry point for search engines to crawl and index your content.

This means that all the variations of your content, such as different filters, sorting options, or pagination, have their own URLs, making it easier for search engines to discover and rank your pages appropriately.

In simple terms, imagine your website is like a big library, and each URL is like a unique bookshelf. When you organize your books (content) on different bookshelves (URLs), it's easier for people (search engines) to find the specific book (content) they're looking for.

This organization helps improve your website's visibility and ranking in search engine results because search engines can better understand the structure and relevance of your content.

Using unique URLs for different states or pages also makes it easier for users to share specific content and for search engines to understand the context of that content, which ultimately can lead to better search engine rankings for your website.

So is it something new in Next.js?

Not at all. You can do the URL state management in React too.

URL state management is so underrated in the dev field that it took almost a new Next.js release to make us realize how powerful it is. Otherwise, we'd just keep using states all over the place.

Loading...

0 Comments

glass-bbok

No Comments Yet

Be the first to share your thoughts and start the conversation.

tick-guideNext Lesson

Different URL Parameters in Next.js