Type Route

Type Route

  • Docs
  • GitHub
  • v0.6.0

›Miscellaneous

Introduction

  • Getting Started
  • Simple React Example

Guides

  • Code Splitting
  • Complex Route Parameters
  • Custom Link Behavior
  • Custom Query String
  • Data Fetching
  • Nested and Similar Routes
  • No Match (404)
  • Page Layout
  • Preventing Navigation
  • Programmatic Navigation
  • Redirects
  • Rendering Links
  • Route Parameters
  • Scroll Restoration
  • Server Side Rendering
  • Styling of Links for the Currently Active Route
  • Type Route without React
  • Wildcard Routes
  • Previous Release Docs
  • Guide Missing?

API Reference

    <ParameterDefinition>

    • param

    <RouteDefinition>

    • defineRoute
    • extend

    <RouteGroup>

    • createGroup
    • has

    <Route>

    • action
    • href
    • link
    • name
    • params
    • push
    • replace

    <Router>

    • createRouter
    • useRoute
    • RouteProvider
    • routes
    • session

    Types

    • Link
    • QueryStringSerializer
    • Route
    • RouterOpts
    • SessionOpts
    • ValueSerializer

    Miscellaneous

    • noMatch
    • preventDefaultLinkClickBehavior
Edit

noMatch

The noMatch constant may be returned from the parse function of a ValueSerializer object. It signals to Type Route that the value you're attempting to parse is incompatible with the current ValueSerializer. When noMatch is returned Type Route will not treat a route using this parameter as a match. See the Complex Route Parameters guide for more information.

import { noMatch, ValueSerializer, createRouter, defineRoute, param } from "type-route";

const date: ValueSerializer<Date> = {
  parse(raw) {
    const value = Date.parse(raw);
    
    if (isNaN(value)) {
      return noMatch;
    }

    return new Date(value);
  },
  stringify(value) {
    return value.toISOString();
  }
};

const opts: RouterOpts = {
  session: {
    type: "memory",
    initialEntries: [
      "/date-test/invalid-date"
    ]
  }
}

const { routes, session } = createRouter(opts, {
  dateTest: defineRoute(
    {
      date: param.path.ofType(date)
    },
    p => `/date-test/${p.date}`
  )
});

console.log(session.getInitialRoute().name); // false
← ValueSerializerpreventDefaultLinkClickBehavior →
Type Route is a Type Hero project  ·  Copyright © 2020