MCPcopy Index your code
hub / github.com/AveroLLC/typesafe-react-router

github.com/AveroLLC/typesafe-react-router @v2.2.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.2.4 ↗ · + Follow
11 symbols 19 edges 7 files 0 documented · 0% updated 3y agov2.2.2 · 2019-02-13★ 893 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Typesafe-React-Router

A collection of types and utility functions to facilitate typesafe routing in React-Router.

npm i typesafe-react-router

vscode Note: This gif is using the 1.0 array-style API, rather than spread arguments used in 2.0.

Usage

import { route, param } from 'typesafe-react-router';

export enum RouteNames {
  HOME = "HOME"
  VIEW_ALL = "VIEW_ALL"
  VIEW_DETAILS = 'VIEW_DETAILS'
}

export const Routes = {
  [RouteNames.HOME]: route('home');
  [RouteNames.VIEW_ALL]: route('view')
  [RouteNames.VIEW_DETAILS]: route('view', param('id'))
}

const viewDetailsTemplate = Routes[RouteNames.VIEW_DETAILS].template() // -> /view/:id
const viewDetailsCreate = Routes[RouteNames.VIEW_DETAILS].create({ id: '2' }) // -> /view/2

const viewDetailsCreateERROR = Routes[RouteNames.VIEW_DETAILS].create({}) // ERROR: property 'id' is missing in type {}

// Usage with React Router
import { Route, Switch } from 'react-router-dom';
import { Home, Summary, Details } from './components'
export class App extends React.PureComponent {
  render() {
    <Switch>
      <Route path={Routes[RouteNames.HOME].template()} component={Home} />
      <Route path={Routes[RouteNames.VIEW].template()} component={Summary} />
      <Route path={Routes[RouteNames.VIEW_DETAILS].template()} component={Details} />
    </Switch>
  }
}

import { Link } from 'react-router-dom';

export class Home extends React.PureComponent {
  render() {



      <h1>Welcome Home!</h1>
      <Link to={Routes[RouteNames.VIEW_DETAILS].create({ id: '3' })} />
      {/* ERROR: property 'id' is missing in type {} */}
      <Link to={Routes[RouteNames.VIEW_DETAILS].create({})} />



  }
}

Extension points exported contracts — how you extend this code

Route (Interface)
(no doc)
src/interfaces/types.ts
PathParam (Interface)
(no doc)
src/interfaces/types.ts

Core symbols most depended-on inside this repo

create
called by 13
src/interfaces/types.ts
route
called by 9
src/route.ts
param
called by 8
src/param.ts
parse
called by 4
src/interfaces/types.ts
isParam
called by 2
src/interfaces/guards.ts
_routeCreator
called by 1
src/route.ts
template
called by 1
src/interfaces/types.ts
parse
called by 0
src/parse.ts

Shape

Function 5
Method 3
Interface 2
Enum 1

Languages

TypeScript100%

Modules by API surface

src/interfaces/types.ts5 symbols
src/route.ts2 symbols
src/route.test.ts1 symbols
src/parse.ts1 symbols
src/param.ts1 symbols
src/interfaces/guards.ts1 symbols

For agents

$ claude mcp add typesafe-react-router \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page