What is an URL pathname?
According to MDN web docs “The pathname property of the URL interface represents a location in a hierarchical structure. It is a string constructed from a list of path segments, each of which is prefixed by a / character. If the URL has no path segments, the value of its pathname property will be the empty string.”
For example, [Tex]w3wiki.org/[/Tex] has one path segment which is a empty string as there is nothing after /.
The final segment of a pathname is referred as slug. For example, [Tex]xyz.com/post/3[/Tex], here the pathname is [Tex]/post/3[/Tex] and [Tex]/3[/Tex] is the slug.
How to Get URL pathname in Next.js?
Next.js is a React framework used to build sophisticated full-stack web applications. Since the introduction of the App router, Next.js’s popularity has skyrocketed, making it the most widely used React.js framework. When developing applications, we frequently require URL pathnames to enable different features for specific users.
In this article, we will explore how to obtain URL pathnames in Next.js applications.
Table of Content
- What is an URL pathname
- Get URL pathname in Pages router
- Get URL pathname in App router
- Conclusion
Contact Us