can this be further simplified
i have run into an issue in an astro template and am gonna make a pr with the fix. but the current solution feels hacky
can this be simplified somehow? should i just make a pr and let the maintainers review it?
58 Replies
Excuse me but why are you first removing the slash and then adding it back
cuz u only add it back if href==="/"
you could check b4 removing w/ turnary ig
okay so Astro.url.pathname returns "/" for home and "/blog/" for blog and href is only "/blog" so they don't match and it doesn't become acting
so i have to remove the trailing slash
but then in home "/" becomes ""
so i have to add it back just for home
I’d test with RegEx if the pathname only contains slash and if not is just trimEnd
should you really put complex regex in a template tho?
astro is really aimed at beginners i think we should keep it as simple as possible
Gonna think, brb I’m a minute
nexxel is this the use you are looking for?
or
tho ^ and $ might need to be replaced with \A and \z
lemme try both of these
this doesn't seem to work :(
i didnt try it myself lol
oh, cuz i didnt reassign after replace maybe
coz astro.url.pathname is always truthy
""
|| compares the length of strings.
isnt pathname for home is '/' ?
wasnt going to assume
Astro.url.pathname returns "/" for home and "/blog/" for blog (C) nexxel
yeah
its always truthy
"" this is returned after the .replace on it
this also doesn't work for home
this works for only home
man javascript is hard <:P_veryweary:827162432778141706>
does home have the
{some url}/
or just /
pathnamejust /
it works in deno, gonna try in astro in a minute
oh wait i didn'tt ry to replace this
lemme try that
like this?
yeah
no wait
/\A\/\z/
okay
it is converting it to
/A/z/
on save🤔
\ is for escaping characters maybe it’s ok without them
this also doesn't work on home
works on others
so weird
maybe i will just make the pr and let the maintainers think of something
RegEx is weird. Well that means home has some other character except /
no it is just /
this works
that proves its just
/
lemme try your thing again wait
this doesn't work
because
lets say we pass /blog as href and /blog/ as pathname
so pathname becaomes /blog/
then we're checking if href === "/", /blog is not equal to /, so the replace isn't exceuted
so isActive is checking for /blog === /blog/this works for me tho
this works on localhost
try on vercel
opened the issue https://github.com/withastro/astro/issues/5248
GitHub
template: navbar
isActive
doesn't work on home page in the person...What version of astro are you using? 1.6.0 Are you using an SSR adapter? If so, which one? n/a What package manager are you using? pnpm What operating system are you using? WSL Ubuntu Describe the ...
if u dont care about href is specifically '/'
AstroUrlPathname.replace(/\/$/, "") || '/'
right?ohhh yeah cause after the replace it becomes falsy
did i copy paste wrong then?? you send the snippet here again
lemme try
im pretty sure href does matter tho
yeah cause it has to be "/" for that
idk man doesn't work https://astro-blog-template-navbar-issue-repro-git-possible-fix-nexxeln.vercel.app/
My personal website.
Welcome to my website!
is this wrong?
backslash between ^ and /
regexes are cringe
/^\/$/
why is it auto stripping it out on save???
wtffff
idk, it doesn't for me neither in nvim nor vscode
doesn't work still
im shit in astro, how do you get href as a prop? I just have this code in /pages/index.astro
OOOOOOOH I UNDERSTOOD
delete fucking quotes
just
match(/^\/$/)
this is the prop
ohh
it looks for string and not for regex
oh dude
that works on save
now lemme deploy
i am so dumb
idk how to javascript
fr fr
no, thats that moment when i stare at this and my brain doesn't proceed it either
and then that lightbulb moment
this shit works yeahhh https://astro-blog-template-navbar-issue-repro-putckyo19-nexxeln.vercel.app/
My personal website.
Welcome to my website!
lets gooo
updated the issue