All Projects → dollarshaveclub → react-passage

dollarshaveclub / react-passage

Licence: MIT license
Link and Redirect to routes safely in your react applications 🌄

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-passage

README-ecoleta
🎁 Três modelos de README com o Projeto criados para o blog da @Rocketseat 🚀
Stars: ✭ 179 (+193.44%)
Mutual labels:  react-router, context-api
Google-Clone
A Google Clone which built with ReactJS. When you click Gmail button, you will be directed to my other project, Gmail Clone. You can search whatever you want and send realtime emails by clicking Gmail button!
Stars: ✭ 37 (-39.34%)
Mutual labels:  react-router, context-api
Tomatobean
集成react + react-router + react-redux的轻量级前端框架。提供keep-live功能,快速构建项目。在构建中大型项目时优势明显。
Stars: ✭ 15 (-75.41%)
Mutual labels:  react-router
react-without-redux
React State Management without Redux
Stars: ✭ 33 (-45.9%)
Mutual labels:  context-api
react-spa-template
This is a sample template for single page applications built using React + Router to work with webpack dev server
Stars: ✭ 19 (-68.85%)
Mutual labels:  react-router
react-laravel
A simple crud based laravel app to learn how to use react with laravel.
Stars: ✭ 43 (-29.51%)
Mutual labels:  react-router
Client
TRPG即时IM通讯软件客户端,基于React 与 React Native + Redux技术
Stars: ✭ 118 (+93.44%)
Mutual labels:  react-router
razzle-template
SSR template with React, Effector, TypeScript, ReactRouter, and StyledComponents
Stars: ✭ 62 (+1.64%)
Mutual labels:  react-router
fifa
React + Node.js + socket.io -- A turn-based multiplayer game-client based on FIFA
Stars: ✭ 26 (-57.38%)
Mutual labels:  react-router
socialApp-MERN
Social Networking web app similar to Instagram.
Stars: ✭ 35 (-42.62%)
Mutual labels:  react-router
temperjs
State management for React, made simple.
Stars: ✭ 15 (-75.41%)
Mutual labels:  context-api
react
react 项目骨架
Stars: ✭ 12 (-80.33%)
Mutual labels:  react-router
react-authentication-in-depth
Example of User Authentication using React with React Router and AWS Amplify
Stars: ✭ 61 (+0%)
Mutual labels:  react-router
React-Playground
Learning reactjs from the ground up (router, redux, thunk, hooks, context, portals, and functional components)
Stars: ✭ 15 (-75.41%)
Mutual labels:  react-router
typesafe-react-router
Utility functions to help facilitate type-safe routing with react-router
Stars: ✭ 90 (+47.54%)
Mutual labels:  react-router
keep-graph
Keep Graph is a open source clone of Google Keep. It's built on top of React and GraphQL.
Stars: ✭ 29 (-52.46%)
Mutual labels:  react-router
react-formular
This libraray is an experimental approach to bind forms and its inputs and editors together using the new React Context API. It aims to be fully customizable and composable. It´s only a set of Higher-Order-Components. Because of the decoupled nature, Middlewares makes it easy to build custom Validations, Security Guards and other data interceptors.
Stars: ✭ 43 (-29.51%)
Mutual labels:  context-api
sunrise
The rise of a new project with React, Redux-Saga and React-Router
Stars: ✭ 13 (-78.69%)
Mutual labels:  react-router
react-ssr-starter
🔥 ⚛️ A React boilerplate for a universal web app with a highly scalable, offline-first foundation and our focus on performance and best practices.
Stars: ✭ 40 (-34.43%)
Mutual labels:  react-router
douban-movie-electron
This is electron app for douban movie
Stars: ✭ 19 (-68.85%)
Mutual labels:  react-router


npm version

Passage helps when linking or redirecting to routes that may or may not be in your react app.

The idea is simple: Wrap Passage around your routes so it knows what routes have been defined in your app. Then, using the Link and Redirect components from Passage will honor the HTML5 history API if the route is within your app, otherwise falling back to other means such as anchor tags or location redirects.

Note: There may be some issues with nested react routes. Read more here.

Installing

Install via NPM:

npm i @dollarshaveclub/react-passage@latest --save

Usage

Passage provides three exports.

  • A Passage component used for identifying routes in your app
  • A Link component, use this to render react links internal/external routes
  • A Redirect component, use this to redirect to internal/external routes

Wrap the Passage component around your routes

import React from 'react'
import { BrowserRouter, Route, Switch } from 'react-router-dom'

import { Passage } from '@dollarshaveclub/react-passage'

const App = () => (
  <Passage>
    <BrowserRouter>
      <Switch>
        <Route exact path="/" component={Home} />
        <Route path="/about" component={About} />
        <Route path="/topics" component={Topics} />
      </Switch>
    </BrowserRouter>
  </Passage>
)

The Passage component accepts an optional prop called targets. This is an array of components that you want to search for within your routes file. It has a value of [Route] by default.

const App = () => (
  <Passage targets={[ Route, MyCustomRoute ]}>
    <BrowserRouter>
      <Switch>
        <MyCustomRoute exact path="/" component={Home} />
        <MyCustomRoute path="/about" component={About} />
        <Route path="/topics" component={Topics} />
      </Switch>
    </BrowserRouter>
  </Passage>
)

Leverage Passage Links and Redirects

import React from 'react'

import {
  Link,
  Redirect,
} from '@dollarshaveclub/react-passage'

// Renders a React Router Link tag if it can, otherwise falls back to an anchor tag
const aboutExample = () => (<Link to='/about'>About</Link>)

// Force Link to render an anchor tag
const externalExample = () => (<Link external to='https://www.google.com'>Google</Link>)

// Redirects with react-history if route exists, otherwise, uses window.location.assign
const externalExample = () => (<Redirect to='/external-path' />)

// Change how you redirect
const changeRedirectExample = () => (
  <Redirect to='/new-website' via={(to) => window.location.href = to} />
)

License

MIT

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].