Using SvelteKit (but is the same for each JS framework) I have a menu like this:
const menu = [
{ name: "players", url: "/players" },
{ name: "team", url: "/players/team" },
{ name: "player detail", url: "/players/[id]" }, // id can be a string here
{ name: "player's team coach detail", url: "/players/[id]/coach" }, // id can be a string here
// and so on...
];
and I'm using it with a for loop using an <a> tag:
<a href="{url}" class:current="{page.url.pathname.startsWith(url)}">
{name}
</a>
As you can see the class:current part is wrong because it marks as current all these urls:
/playersand/players/1and so on player 2, 3.../players/team, this is not correct for me
This is not what I need.
I need a way to exclude the /players/team and the coach one.
Is there a way without using regexes?
page.url.pathnameandurl? I want to know if the possibility ofclass:current="{url.startsWith(page.url.pathname)}"works