alloc / alloc/saus

`parseRoutePattern` plugin hook

Aperta
#59 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
backlog plugin API
Lingua principale
TypeScript
Stelle
38
Fork
1
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

We currently use the `regexparam` library to parse route patterns, but it would be cool if plugins can override this and even provide support for values other than strings (eg: RegExp or options object).

https://github.com/alloc/saus/blob/052b3cc847c131bde25a2c463c59f858ad67c7c4/src/core/routes.ts#L96

The plugin hooks would work a lot like `resolveId` does.
```ts
const plugin: import("saus").Plugin = {
// The hook receives a route pattern and the route's config object,
// which should also be customizable through the plugin API.
parseRoutePattern(route, config) {
if (route instanceof RegExp) {
return {
// Match against a page path.
test: path => route.test(path),
// Render a page path for this route.
render: params => {
// TODO: inject our `params` into the `route.source` somehow
},
}
}

// Return falsy to defer to the next plugin hook.
return null
}
}
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.