[Feature] Allow optional permutations when exclusive matchFilters are present
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- typescript
- Ambito
- frontend
Direzione di ricerca
Inizia con la funzione expandOptionals mostrata nell’issue e traccia come i percorsi da essa generati vengono combinati con matchFilters. Confronta le espansioni ordinate attuali con l’array di percorsi permutato esplicitamente nell’esempio. Il lavoro è completato quando matchFilters mutuamente esclusivi abilitano le permutazioni opzionali equivalenti senza richiedere ai chiamanti di elencare manualmente ogni percorso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
I was having issues with a routing setup where I have multiple optionals in a row in a path, but each has exclusive matchFilters to differentiate them. I looked through the code and found:
export function expandOptionals(pattern: string): string[] {
let match = /(\/?\:[^\/]+)\?/.exec(pattern);
if (!match) return [pattern];
let prefix = pattern.slice(0, match.index);
let suffix = pattern.slice(match.index + match[0].length);
const prefixes: string[] = [prefix, (prefix += match[1])];
// This section handles adjacent optional params. We don't actually want all permuations since
// that will lead to equivalent routes which have the same number of params. For example
// `/:a?/:b?/:c`? only has the unique expansion: `/`, `/:a`, `/:a/:b`, `/:a/:b/:c` and we can
// discard `/:b`, `/:c`, `/:b/:c` by building them up in order and not recursing. This also helps
// ensure predictability where earlier params have precidence.
while ((match = /^(\/\:[^\/]+)\?/.exec(suffix))) {
prefixes.push((prefix += match[1]));
suffix = suffix.slice(match[0].length);
}
return expandOptionals(suffix).reduce<string[]>(
(results, expansion) => [...results, ...prefixes.map(p => p + expansion)],
[]
);
}
And while I understand the sentiment in the comment, I believe this design should be rethought for routes where there are exclusive matchFilters for each of the optionals. For example, the case where you have:
const matchFilters = {
a: ["hello","world"],
b: ["foo","bar"],
c: /^\d+$/
}
// ...
<Route path="/:a?/:b?/:c?" matchFilters={matchFilters} /* ... */ />
// ...
There is no reason why all permutations of this route shouldn't be available, as the matchFilters for all three routes are mutually exclusive. A workaround for this is to use an array of paths with only one optional per path. When used with matchFilters this technique allows the functionality, but requires manually permuting the list of optionals to create the array -- for example the above becomes:
<Route path={["/:a/:b/:c?", "/:a/:c?", "/:b/:c?", "/:c?"]} matchFilters={matchFilters} />
which works as described.
Your Example Website or App
n/a
Steps to Reproduce the Bug or Issue
nothing to reproduce -- current functionality is working as intended, would just be nice if matchFilters were taken into account when generating optional routes
Expected behavior
When matchFilters are present, allow permutations of optional parameters as long as the matchFilters for all parameters are mutually exclusive
Screenshots or Videos
No response
Platform
n/a
Additional context
No response
- Lingua principale
- TypeScript
- Stelle
- 1.3k
- Fork
- 180
- Merge medio
- 1g 13h
- PR unite (30g)
- 19
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di solidjs/solid-router
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
solidjs/solid-router#613 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
solidjs/solid-router#605 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 78/100
solidjs/solid-router#603 · 1 commento ·
-
<A> costs ~6us of server CPU per instance during SSR (20x a plain <a>), mostly mergeProps/splitProps Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
solidjs/solid-router#583 ·
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
solidjs/solid-router#569 · 3 commenti ·
Tutte le issue di solidjs/solid-router
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
mksglu/context-mode#1200 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
jaegertracing/jaeger-ui#4506 ·
-
area:desktop area:ui bug platform:macos
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
anthropics/claude-code#96687 ·
-
good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
AOSSIE-Org/DebateAI#582 · 2 commenti ·