All Projects → AveroLLC → typesafe-react-router

AveroLLC / typesafe-react-router

Licence: Apache-2.0 license
Utility functions to help facilitate type-safe routing with react-router

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to typesafe-react-router

Frontend
마음을 잇는 현명한 소비 '잇다'🤝
Stars: ✭ 19 (-78.89%)
Mutual labels:  react-router
react
react 项目骨架
Stars: ✭ 12 (-86.67%)
Mutual labels:  react-router
Client
TRPG即时IM通讯软件客户端,基于React 与 React Native + Redux技术
Stars: ✭ 118 (+31.11%)
Mutual labels:  react-router
luban
a scaffold to create a react app
Stars: ✭ 22 (-75.56%)
Mutual labels:  react-router
React-Playground
Learning reactjs from the ground up (router, redux, thunk, hooks, context, portals, and functional components)
Stars: ✭ 15 (-83.33%)
Mutual labels:  react-router
ts-types-utils
Type utilities for typescript
Stars: ✭ 55 (-38.89%)
Mutual labels:  typesafe
react-demo-projects
Sample React Projects built with different libraries such as Redux, Apollo, React Router etc.
Stars: ✭ 83 (-7.78%)
Mutual labels:  react-router
material-ui-Link-within-MenuItem
Example for how to use `react-router/Link` within `material-ui/MenuItem`
Stars: ✭ 19 (-78.89%)
Mutual labels:  react-router
react-laravel
A simple crud based laravel app to learn how to use react with laravel.
Stars: ✭ 43 (-52.22%)
Mutual labels:  react-router
sunrise
The rise of a new project with React, Redux-Saga and React-Router
Stars: ✭ 13 (-85.56%)
Mutual labels:  react-router
razzle-template
SSR template with React, Effector, TypeScript, ReactRouter, and StyledComponents
Stars: ✭ 62 (-31.11%)
Mutual labels:  react-router
Tomatobean
集成react + react-router + react-redux的轻量级前端框架。提供keep-live功能,快速构建项目。在构建中大型项目时优势明显。
Stars: ✭ 15 (-83.33%)
Mutual labels:  react-router
socialApp-MERN
Social Networking web app similar to Instagram.
Stars: ✭ 35 (-61.11%)
Mutual labels:  react-router
react-webpack2-skeleton
Get started with React with Webpack2, React-Router, Redux, Code Splitting and Server Rendering
Stars: ✭ 59 (-34.44%)
Mutual labels:  react-router
react-authentication-in-depth
Example of User Authentication using React with React Router and AWS Amplify
Stars: ✭ 61 (-32.22%)
Mutual labels:  react-router
react-antd
基于react + redux + immutable + less + ES6/7 + webpack2.0 + fetch + react-router + antd实现的SPA后台管理系统模板
Stars: ✭ 320 (+255.56%)
Mutual labels:  react-router
PERN-Advanced-Starter
Advanced PERN stack starter kit (PostgresSQL, Express, React, & Node), complete with ESLint, Webpack 4, Redux, React-Router, and Material-UI kit.
Stars: ✭ 51 (-43.33%)
Mutual labels:  react-router
fifa
React + Node.js + socket.io -- A turn-based multiplayer game-client based on FIFA
Stars: ✭ 26 (-71.11%)
Mutual labels:  react-router
freecli
Command line parsing library using Free Applicative
Stars: ✭ 29 (-67.78%)
Mutual labels:  typesafe
react-spa-template
This is a sample template for single page applications built using React + Router to work with webpack dev server
Stars: ✭ 19 (-78.89%)
Mutual labels:  react-router

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() {
    <div>
      <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({})} />
    </div>
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].