Remix
Remix

routes

Typed route definitions and URL helpers for Remix apps.

Features

  • Build named route maps with strong route-pattern typing
  • Generate hrefs from route definitions
  • Compose nested route maps and reusable resource route groups
  • Define routes with HTTP method helpers like get, post, put, and del

Installation

npm i remix

Usage

Define your app routes in one place and import the route map wherever you need type-safe href generation or router mappings.

import { form, get, route } from 'remix/routes'

export const routes = route({
  home: '/',
  posts: {
    index: get('/posts'),
    show: get('/posts/:slug'),
    search: form('/posts/search'),
  },
})

routes.posts.show.href({ slug: 'hello-world' })

Route Maps

Use route to create named route maps. Nested objects become nested route groups, and string values create routes that accept any request method.

import { route } from 'remix/routes'

export const routes = route({
  home: '/',
  about: {
    index: '/about',
    company: '/about/company',
  },
})

You can also build a route group with a shared base pattern.

import { get, route } from 'remix/routes'

export const posts = route('/posts', {
  index: get('/'),
  show: get('/:slug'),
  edit: get('/:slug/edit'),
})

Method Helpers

Use method helpers when a route should only match a specific HTTP method.

import { del, get, post, put, route } from 'remix/routes'

export const routes = route({
  posts: {
    index: get('/posts'),
    create: post('/posts'),
    update: put('/posts/:id'),
    destroy: del('/posts/:id'),
  },
})

Forms And Resources

Use form for paired GET and submit-action routes, and resource or resources for conventional CRUD route groups.

import { form, resources, route } from 'remix/routes'

export const routes = route({
  login: form('/login'),
  posts: resources('/posts', { param: 'slug' }),
})

Related Packages

  • fetch-router maps route definitions to Fetch API request handlers.
  • route-pattern provides the URL pattern matching and href generation used by route definitions.

Related Work

License

See LICENSE