[Feature] Allow optional permutations when exclusive matchFilters are present
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- typescript
- Área
- frontend
Línea de trabajo
Comienza con la función expandOptionals mostrada en el issue y sigue cómo sus rutas generadas se combinan con matchFilters. Compara las expansiones ordenadas actuales con el array de rutas permutado explícitamente en el ejemplo. Se considera terminado cuando unos matchFilters mutuamente excluyentes habilitan las permutaciones opcionales equivalentes sin requerir que los llamadores enumeren manualmente cada ruta.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.3k
- Forks
- 180
- Merge medio
- 1 d 13 h
- PR fusionados (30 d)
- 19
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de solidjs/solid-router
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
solidjs/solid-router#613 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
solidjs/solid-router#605 · 1 comentario ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 78/100
solidjs/solid-router#603 · 1 comentario ·
-
<A> costs ~6us of server CPU per instance during SSR (20x a plain <a>), mostly mergeProps/splitProps Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
solidjs/solid-router#583 ·
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
solidjs/solid-router#569 · 3 comentarios ·
Todos los issues de solidjs/solid-router
Issues similares
-
VerificationGate: ATTRIBUTION quote guard never matches a normal quotation (\b around the quote) Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
danielmiessler/LifeOS#2234 ·
-
T: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
-
Mend: dependency security vulnerability untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100