Skip to content

Ability to manually register non-discoverable routes #142

@jackfrosty908

Description

@jackfrosty908

I may have missed something in the docs, but is there a way to manually register routes?

Issue I'm facing

I am using next-typesafe-url in a project that serves a single-page application (the TinaCMS admin UI) from the /public directory. The route to access this application is /admin/index.html.

Because this path is served as a static asset from the public folder, it is not part of the Next.js routing system that next-typesafe-url's CLI scans. As a result, this route is not included in the generated types, and I cannot use the $path function to create type-safe links to it.

It would be fantastic to have a way to manually register additional routes that the CLI cannot discover automatically. A possible implementation could be a configuration file (e.g., typesafe-url.config.ts) where users can define an array of custom static or dynamic routes.

A super rough idea:

Have a way to manually register additional routes that the CLI cannot discover automatically. A possible implementation could be a configuration file (e.g., typesafe-url.config.ts) where users can define an array of custom static or dynamic routes.

For example:

// typesafe-url.config.ts
import { z } from "zod";

export default {
  /**
   * Manually define routes that are not discoverable by the CLI.
   */
  manualRoutes: {
    // For static routes in /public
    "/admin/index.html": {
        // This would be treated as a StaticRoute
    },
    // Could also potentially support defining schemas for external dynamic routes
    "/external-blog/:slug": {
      routeParams: z.object({ slug: z.string() })
    }
  }
};

The CLI could then read this configuration and merge these manualRoutes with the routes it discovers from the file system to create a complete routing map.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions