alloc / alloc/saus

`parseRoutePattern` plugin hook

未關閉
#59 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
backlog plugin API
主要語言
TypeScript
星號
38
分支
1
PR 合併指標
30 天內沒有已合併 PR

描述

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
}
}
```

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。