sveltejs / sveltejs/kit

Get `RouteId` string from a route at run/compiletime

Open
#13,253 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

I don't want to rely on magic strings to do my routing.

Describe the proposed solution
import {routeId} from '$routes/foo/[bar]/baz';

routeId === "/foo/[bar]/baz;"
Alternatives considered

Currently I am doing

/foo/[bar]/baz/index.ts

import type { RouteId } from "./$types";

export const routeId: RouteId = "/foo/[bar]/baz";

Which is /okay/ becasue typescript tells me off if the route has changed, but it would be good if there was a builtin.

I'm currently using oob sveltekit so I'm not sure if there is an acceptable generalised solution for e.g. custom routing.

Importance

nice to have

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with /foo/[bar]/baz/index.ts and its ./ $types import to understand the current typed RouteId pattern. Trace how route IDs are generated or exposed, then verify that the proposed routeId entry point provides the route ID at compile time and remains type-safe when the route changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.