Type Route

Type Route

  • Docs
  • GitHub
  • v0.6.0

›<Router>

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

createRouter

createRouter(routeDefinitions: RouteDefinitionBuilderCollection): Router
createRouter(routerOpts: RouterOpts, routeDefinitions: RouteDefinitionBuilderCollection): Router

Initializes a router. By default the underlying session history instance which powers Type Route will be configured according to the environment your code is running in. This means Type Route should work out of the box in both browser and non-browser environments such as React Native. You can always reconfigure the session history instance to cover other use cases (such as server-side rendering).

Example

const { routes } = createRouter({
  home: defineRoute("/"),
  postList: defineRoute(
    {
      page: param.query.optional.number
    },
    p => `/post`
  ),
  post: defineRoute(
    {
      postId: param.path.string
    },
    p => `/post/${p.postId}`
  )
});

createRouter will create a Router object. Immediately destructuring this Router object into the properties your application needs is the recommended style. The exact properties available will differ depending on if you're using type-route or type-route/core. For details on what is returned by each checkout the Type Route without React guide.

← replaceuseRoute →
Type Route is a Type Hero project  ·  Copyright © 2020