Skip to content

feat(router): add type-safe TanStack-style route targets#61

Open
nakasyou wants to merge 2 commits into
mainfrom
feat/typed-routing-api
Open

feat(router): add type-safe TanStack-style route targets#61
nakasyou wants to merge 2 commits into
mainfrom
feat/typed-routing-api

Conversation

@nakasyou
Copy link
Copy Markdown
Member

Summary

  • add typed route target support with createRouteHref and buildRoutePath
  • extend Navigate to accept object-style route targets ({ to, params, search, hash, replace })
  • support object-style route targets directly in <Link /> (to + params/search/hash)
  • export new router helpers/types from core/mod.ts
  • add runtime and type-oriented tests for route param inference and href generation

Verification

  • bunx vp test --run packages/eclipsa/core/router.test.tsx packages/eclipsa/core/router-types.test.ts

Copilot AI review requested due to automatic review settings March 18, 2026 00:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and normalizeNavigateInput in router-shared.ts.
  • Updates runtime navigation APIs to accept either string hrefs or RouteTarget objects.
  • Extends Link to accept either href or 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 thread packages/eclipsa/core/router.tsx Outdated
Comment on lines +35 to +40
interface LinkRouteTargetProps<Path extends string = string> {
hash?: string
href?: never
params?: RoutePathParams<Path>
search?: RouteSearchParamsInput
to: Path
Comment thread packages/eclipsa/core/router.tsx Outdated
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)
Comment thread packages/eclipsa/core/router-shared.ts Outdated

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
})
})
@nakasyou
Copy link
Copy Markdown
Member Author

@codex レビュー

@nakasyou
Copy link
Copy Markdown
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>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

@copilot resolve the merge conflicts in this pull request

マージコンフリクトを解消し、origin/main を取り込んだマージコミット 0ab514c を反映しました。router まわり(router.tsx / runtime.ts / mod.ts)の衝突を解消して、対象テストも再実行済みです。

}, {})

const resolveVariant = (value: unknown, props: MotionProps): Record<string, unknown> | null => {
if (!value || value === true || value === false) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants