feat(router): add type-safe TanStack-style route targets#61
Open
nakasyou wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds “typed routing” primitives to Eclipsa core so Link and Navigate can work with route targets (path templates + params/search/hash) and provides shared helpers to construct typed paths/hrefs.
Changes:
- Introduces
RouteTarget,RoutePathParams,buildRoutePath,createRouteHref, andnormalizeNavigateInputinrouter-shared.ts. - Updates runtime navigation APIs to accept either
stringhrefs orRouteTargetobjects. - Extends
Linkto accept eitherhrefor a route target (to/params/search/hash) and adds tests for typed route helpers.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/eclipsa/core/runtime.ts | Updates internal navigate implementations to normalize `string |
| packages/eclipsa/core/router.tsx | Extends Link props to accept route targets and resolves them into href. |
| packages/eclipsa/core/router.test.tsx | Adds SSR tests for route-target Link usage and route helper behavior. |
| packages/eclipsa/core/router-types.test.ts | Adds type-safety assertions for typed routing helpers. |
| packages/eclipsa/core/router-shared.ts | Introduces typed route param/search types plus helpers to build paths/hrefs and normalize navigate inputs. |
| packages/eclipsa/core/mod.ts | Re-exports new helpers and routing types from the public core entrypoint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+35
to
+40
| interface LinkRouteTargetProps<Path extends string = string> { | ||
| hash?: string | ||
| href?: never | ||
| params?: RoutePathParams<Path> | ||
| search?: RouteSearchParamsInput | ||
| to: Path |
Comment on lines
+66
to
+71
| return createRouteHref({ | ||
| to: props.to, | ||
| params: props.params as RoutePathParams<string> | undefined, | ||
| search: props.search, | ||
| hash: props.hash, | ||
| } as RouteTarget) |
|
|
||
| export interface Navigate { | ||
| (href: string, options?: NavigateOptions): Promise<void> | ||
| <Path extends string>(target: RouteTarget<Path>): Promise<void> |
Comment on lines
+1
to
+34
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { buildRoutePath, createRouteHref, type RoutePathParams } from './router-shared.ts' | ||
|
|
||
| describe('router typed APIs', () => { | ||
| it('keeps type-safe path parameter requirements', () => { | ||
| const validParams: RoutePathParams<'/posts/[id]/[[tab]]/[...rest]'> = { | ||
| id: '42', | ||
| rest: ['comments', 'latest'], | ||
| } | ||
|
|
||
| const href = createRouteHref({ | ||
| to: '/posts/[id]/[[tab]]/[...rest]', | ||
| params: validParams, | ||
| hash: 'tail', | ||
| }) | ||
|
|
||
| expect(href).toBe('/posts/42/comments/latest#tail') | ||
| expect(buildRoutePath('/posts/[id]', { id: '99' })).toBe('/posts/99') | ||
|
|
||
| const ensureTypeErrors = () => { | ||
| // @ts-expect-error missing required path params | ||
| createRouteHref({ to: '/posts/[id]' }) | ||
|
|
||
| // @ts-expect-error rest params are required on [...rest] | ||
| buildRoutePath('/posts/[id]/[...rest]', { id: '10' }) | ||
|
|
||
| // @ts-expect-error unknown params are rejected | ||
| buildRoutePath('/posts/[id]', { id: '1', extra: 'x' }) | ||
| } | ||
|
|
||
| void ensureTypeErrors | ||
| }) | ||
| }) |
Member
Author
|
@codex レビュー |
Member
Author
|
@copilot resolve the merge conflicts in this pull request |
Agent-Logs-Url: https://github.com/pnsk-lab/eclipsa/sessions/2d95379f-f5e2-4442-b712-ef40c471f8ab Co-authored-by: nakasyou <79000684+nakasyou@users.noreply.github.com>
Contributor
マージコンフリクトを解消し、 |
| }, {}) | ||
|
|
||
| const resolveVariant = (value: unknown, props: MotionProps): Record<string, unknown> | null => { | ||
| if (!value || value === true || value === false) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
createRouteHrefandbuildRoutePathNavigateto accept object-style route targets ({ to, params, search, hash, replace })<Link />(to+params/search/hash)core/mod.tsVerification
bunx vp test --run packages/eclipsa/core/router.test.tsx packages/eclipsa/core/router-types.test.ts