diff --git a/docs/guide/type-safety.md b/docs/guide/type-safety.md index 4f3de869e..d9abf30ba 100644 --- a/docs/guide/type-safety.md +++ b/docs/guide/type-safety.md @@ -335,7 +335,7 @@ import { routeUrl } from 'void/routes'; ::: -Links also accept same-page queries and hashes (`?page=2`, `#comments`), and `http://`, `https://`, `mailto:`, and `tel:` URLs. Use absolute paths within your app; relative paths such as `../settings` are rejected. Static path segments accept raw text such as `/café menu` or uppercase percent encoding such as `/caf%C3%A9%20menu`. +Links also accept same-page queries and hashes (`?page=2`, `#comments`), and `http://`, `https://`, `mailto:`, and `tel:` URLs. A `routeUrl()` result takes the same query or hash suffix, so `` `${routeUrl('/users/[id]', { params: { id } })}?tab=activity` `` is checked too. Use absolute paths within your app; relative paths such as `../settings` are rejected. Static path segments accept raw text such as `/café menu` or uppercase percent encoding such as `/caf%C3%A9%20menu`. With `routing.typedRoutes`, URLs handled only by root dynamic routes (`/[slug]`, `/[...slug]`, or `/[...]`) require `routeUrl()`, for example `routeUrl('/[...slug]', { params: { slug: 'dashboard' } })`. Other declared routes still accept checked URL strings. For a custom 404 page, use [`_not-found`](./pages-routing/errors.md#missing-pages). diff --git a/packages/void/src/codegen/route-types.ts b/packages/void/src/codegen/route-types.ts index 7578b4ccf..c7c1511f4 100644 --- a/packages/void/src/codegen/route-types.ts +++ b/packages/void/src/codegen/route-types.ts @@ -188,9 +188,10 @@ export function generateRouteTypes( ' type RoutePathUrl = RoutePatternUrl>;', ); lines.push(' type BuiltRouteUrl = string & { readonly __voidRouteUrl: true };'); + lines.push(' type RouteUrlBase = BuiltRouteUrl | RoutePathUrl;'); lines.push(' type TypedRoutes = RouteTypesConfig extends { typedRoutes: true } ? true : false;'); lines.push(' export type RouteUrl = TypedRoutes extends true'); - lines.push(' ? BuiltRouteUrl | RoutePathUrl | `${RoutePathUrl}${"?" | "#"}${string}`'); + lines.push(' ? RouteUrlBase | `${RouteUrlBase}${"?" | "#"}${string}`'); lines.push(' : string;'); lines.push(' export type Href = TypedRoutes extends true'); lines.push( diff --git a/packages/void/src/runtime/routing/route-url.ts b/packages/void/src/runtime/routing/route-url.ts index 75c631804..40a219f0b 100644 --- a/packages/void/src/runtime/routing/route-url.ts +++ b/packages/void/src/runtime/routing/route-url.ts @@ -112,13 +112,16 @@ type RoutePathUrl = RoutePatternUrl