Peter Mekhaeil

Get current page URL in Astro

Astro.url returns the current page URL from the Request object. The return value is a URL object which contains properties like pathname and origin.

const currentPath = Astro.url.pathname;

Useful when you need to highlight navigation links based on current page:

<a href="/me" class={currentPath === '/me' ? 'active' : ''}>
  About Me
</a>