github remix-run/remix fetch-router@0.5.0
fetch-router v0.5.0

13 hours ago
  • Add formData middleware for parsing FormData objects from the request body

    import { formData } from '@remix-run/fetch-router/form-data-middleware'
    
    let router = createRouter()
    
    router.use(formData())
    
    router.map('/', ({ formData, files }) => {
      console.log(formData) // FormData from the request body
      console.log(files) // Record<string, File> from the request body
      return new Response('Home')
    })
  • Add storage.has(key) for checking if a value is stored for a given key

  • Add next(moreContext) API for passing additional context to the next middleware or handler in the chain

  • Move logger middleware to @remix-run/fetch-router/logger-middleware export

  • Add json and redirect response helpers

    import { json, redirect, createRouter } from '@remix-run/fetch-router'
    
    let router = createRouter()
    
    router.map('/api', () => {
      return json({ message: 'Hello, world!' })
    })
    
    router.map('/*path/', ({ params }) => {
      // Strip all trailing slashes from URL paths
      return redirect(`/${params.path}`, 301)
    })

    redirect also accepts a Route object for type-safe redirects:

    let routes = createRoutes({
      home: '/',
    })
    
    let response = redirect(routes.home)

    Note: the route must support GET (or ANY) for redirects and must not have any required params, so the helper can safely construct the redirect URL.

Don't miss a new remix release

NewReleases is sending notifications on new releases.