Giter Club home page Giter Club logo

ipfs-react-router's Introduction

IPFS React Router

npm GitHub Workflow Status

Better routing for IPFS websites when using React Router

An alternative to BrowserRouter or HashRouter in React Router that sets the basename (website root url path) dependent on how the site is being served over IPFS.

A site using the IpfsRouter can be served with working routing from all of the following:

Out of the box BrowserRouter will only allow one basename, forcing you to use HashRouter if you are intending to serve the site over an IPFS HTTP gateway. IpfsRouter scans the current url to establish which context it is being used in: domain root, IPFS over public gateway, IPNS over public gateway, then sets the basename accordingly.

Install

npm install --save ipfs-react-router

Usage

React Router expects a top level Router component to provide access to the history API. IpfsRouter is a drop in replacement for BrowserRouter.

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

function App() {
  return (
    <div className="App">
      <IpfsRouter>
        <Switch>
          <Route exact path="/">
            <h2>Homepage</h2>
          </Route>
          <Route path="/another">
            <h2>Another</h2>
          </Route>
          <Route path="*">
            <p>Not found</p>
          </Route>
        </Switch>
      </IpfsRouter>
    </div>
  )
}

export default App

Contributing

PRs accepted.

To run the tests (jest):

yarn test

Eslint and prettier are used for linting:

yarn lint

To auto-fix linting issues:

yarn lint:fix

License

MIT © John Kane

ipfs-react-router's People

Contributors

dependabot[bot] avatar kanej avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.