#If is page function to check current page in the Astro?

5 messages · Page 1 of 1 (latest)

thick burrow
#

Hello, friends!

I have pages for different local cities, like city1.mdx, city2.mdx. And, I have the select-the-city.astro component in the header. When people click the City link, a dropdown will appear with available cities (which are just internal links to other city pages).

My question is - is there any available function to check the current page? Because as a link, I want to display the current city name. For example: Current city - Almaty (on the almaty.mdx page). On another city page, I want to display the city's name as my link.

In WordPress, I can check the current page with a PHP function like if is_page. Is there any similar function for Astro?

light wrenBOT
#
No-one around right now?

It looks like no-one has responded to your question yet. People might not be available right now or don’t know how to answer your question. Want an answer while you wait? Try asking our experimental bot in #1095492539085230272.

keen sigil
thick burrow
keen sigil
#

BTW, sometimes .pathname can have a trailing slash which can cause obscure bugs between dev and production, I recommend using a regex to trim it off like this: Astro.url.pathname.replace(/\/$/, '')