primocms / primo

Primo is a visual CMS with a built-in code editor, Svelte blocks, and static site generator.
https://primocms.org
MIT License
2.06k stars 543 forks source link

Active state for navigation object #159

Open eikaramba opened 2 years ago

eikaramba commented 2 years ago

Action Performed:

navigate page

Expected Result:

active state of navigation object should change

Actual Result:

active is always false and only visible in the homepage

grafik

Workaround:

nothing i am aware of

Platform:

Where is this issue occurring?

Version Number: desktop 0.4.1

mateomorris commented 2 years ago

Thanks for pointing this out. That's actually a bit of functionality I'd started implementing but never finished because I found a way to do it with JS:

HTML: <a href={link.url} class="link" class:active={isActive(link.url)}>{link.label}</a>

JS:

function isActive(url) {
  const page = window.location.pathname
  if (page === url) return true
  else if (page === '' && url === '/') return true // home
}

(note it only works on the published site & not within primo)

I'll take active out for now but leave the issue open as a feature request since it would be ideal to do this statically.