Feature Request: Add `matchRoutes` Function
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 68/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- react, typescript
- 領域
- frontend
調査の方向性
まず、Wouter の既存のルートマッチングコードと公開エクスポートを見つけ、次にそのマッチング動作を、提案されている regexparam ベースの例と比較します。matchRoutes を公開し、location に対してアクティブなルートを選択し、冗長なマッチングなしで文書化された使用方法をサポートできれば完了です。
索引モデルが issue の本文から書いたものです。
説明
I’d like to request the addition of a matchRoutes function to Wouter. This function is available in react-router, and implementing it in Wouter should require minimal code.
Use Case
The matchRoutes function would allow users to find the active route based on the current location. This is particularly useful for handling layouts or route-based logic efficiently.
Example usage:
const routes = [
{ path: "/foo", component: <div>Foo</div> },
{ path: "/bar", component: <div>Bar</div>, layout: "red" },
];
const layouts = {
default: ({ children }) => <div>{children}</div>,
red: ({ children }) => <div style={{ backgroundColor: "red" }}>{children}</div>,
};
export default function App() {
const [location] = useLocation();
const activeRoute = matchRoutes(routes, location);
const Layout = activeRoute?.layout ? layouts[activeRoute.layout] : layouts.default;
return (
<Layout>
<Routes>
{routes.map((route) => (
<Route key={route.path} path={route.path} element={route.component} />
))}
</Routes>
</Layout>
);
}
Example Implementation
This is the implementation I currently use in my project.
(~160 bytes, unminified)
import { parse } from "regexparam";
function matchRoutes(routes, location) {
return routes.find((route) => {
const regex = parse(route.path);
return regex.pattern.test(location);
});
}
Having this built into the library would prevent redundant loops (like in my example implementation) when matching routes, as Wouter itself already performs route matching internally.
Would love to hear your thoughts on this! Thanks for the awesome work on Wouter! 🚀
- 主要言語
- TypeScript
- スター
- 7.9k
- フォーク
- 193
- 平均マージ
- 6分
- マージ済み PR(30日)
- 3
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
molefrog/wouter のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
-
Links using ~ do not respect `base`対応中かも @molefrog が 24 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
molefrog/wouter の issue をすべて見る
似ている issue
-
b:minor bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
software-mansion/argent#1698 ·
メンテナーはふだん 1 日以内に返信
-
e2e-failure ready-to-code
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
redhat-developer/rhdh-plugin-export-overlays#4624 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
better-auth/better-auth#12132 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
automation missing-model model-sync provider:tinfoil
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
anomalyco/models.dev#12053 ·
メンテナーはふだん 1 日以内に返信
-
o8 next debug build aborts on Glass to Dark appearance switch (nil identifier messaged before check)オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
hurttlocker/o8#5112 ·