You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Two ways to circumvent this bug are the following:
<script>
// 1. duplicate the object for each linkconstactiveLinkStyle1= { className:"underline" };constactiveLinkStyle2= { className:"underline" };
</script>
<!-- 2. duplicate the attributes in the link -->
<ahref="#/settings"use:active={{ className: "underline" }}>Docsets</a>
<ahref="#/settings/settings"use:active={{ className: "underline" }}>Settings</a>
I'd love to create a PR to fix it, but I couldn't set up the environment, so if someone is interested in fixing it, the solution would be as the following:
Instead of this (current code):
exportdefaultfunctionactive(node,opts){// Check optionsif(opts&&(typeofopts=='string'||(typeofopts=='object'&&optsinstanceofRegExp))){// Interpret strings and regular expressions as opts.pathopts={path: opts// <-- ⛔️ this is mutating the object, which is a problem if it's shared}}else{// Ensure opts is a dictionaryopts=opts||{}}
Do this:
exportdefaultfunctionactive(node,opt){// <-- rename the argument to make less changesconstopts={...opt}// <-- clone the object// Check optionsif(opts&&(typeofopts=='string'||(typeofopts=='object'&&optsinstanceofRegExp))){// Interpret strings and regular expressions as opts.pathopts={path: opts}}// <-- no need for else anymore
The text was updated successfully, but these errors were encountered:
Problem
The following snippet will underline both links if I'm at
#/settings
and none if I'm at#/settings/settings
:Two ways to circumvent this bug are the following:
This is happening because the object passed to the
active
function is being directly mutated, so if you share the same object with multiple links, as is the case of my first example where I just want every link to have the same style, every link will get the same path. This is the location of the code: https://github.com/ItalyPaleAle/svelte-spa-router/blob/916347dbef1eb429332bca8375dae549169e665a/active.js#L54:L65Solution
I'd love to create a PR to fix it, but I couldn't set up the environment, so if someone is interested in fixing it, the solution would be as the following:
Instead of this (current code):
Do this:
The text was updated successfully, but these errors were encountered: