ItalyPaleAle / svelte-spa-router

Router for SPAs using Svelte 3
MIT License
1.53k stars 105 forks source link

[Support] - higlight active links #281

Closed andylib93 closed 1 year ago

andylib93 commented 1 year ago

First of all, thank you for this beautiful library - I am enjoying it very much! It is the perfect tool to use routing in Svelte without the need of SvelteKit.

I just have a small question on how to highlight active links: when I have a view for /books/ and this view is highlighted in my navigation bar (which works perfectly), I am having trouble to also highlight the views in /books/1 & /books/2 at the same time.

Is there a one liner, conditional matching or regular expression for both use cases? Because use:active={'/books/*'} highlights only the detail view, not the list view and use:active={'/books/'} highlights only the list view, not the detail views.

ItalyPaleAle commented 1 year ago

You can use a regular expression that matches both: ^\/books(\/(.*?))?$