Code Monkey home page Code Monkey logo

react-router-primitives's Introduction

react-router-primitives

Create cross-platform app routing for React web, React Native and react-sketchapp.

(work in progress and unstable API). Please wait for 0.1.0 release as a minimum for a more stable API.

Getting Started

npm i -S react-router-primitives

API

module.exports = {
  Router,
  Route,
  Link,
  Switch,
  withRouter,
}

Exported Components and Methods

<Router>

A universal router component that uses <BrowserRouter> on web, <SketchRouter> on React Sketch.app and <NativeRouter> on React Native. Thanks to ReactTraining/react-router.

Props

Prop Type Default Note
location [string] | [Location] required String or Location e.g. { key: 'ac3df4', pathname: '/somewhere', search: '?some=search-string', hash: '#howdy', state: [userDefined]: true } }
locations [string[]] | [Location[]] required List of strings or locations
viewport [viewport] required Object: { name: string, width: number, height: number}
children [Node] required

Example

import sketch from 'sketch';
import { Router, Route, Switch } from 'react-router-primitives';
import { RedBox, render } from 'react-sketchapp';

const pageWidth = ...;

// Multi-platform app component (can be imported from component library or other file)
const App = () => (
    <Router
      locations={['/profile/john']}
      viewport={viewports}
    >
      <Switch>
        <Route exact path="/" render={() => <Home />} />
        <Route path="/about" render={() => <About />} />
        <Route path="/profile/:username" render={({ match: { params } }) => <Profile {...params} />} />
        <Route component={NotFound} />
      </Switch>
    </SketchRouter>
  </Page>
);

// Sketch entry-point
export default () => {
  const { selectedPage } = sketch.getSelectedDocument();
  try {
    render((
      <Page name="App" style={{ flexDirection: 'row', flexWrap: 'wrap', maxWidth: pageWidth }}>
        <App />
      </Page>
    ), selectedPage);
  } catch (err) {
    render(<RedBox error={err} />, selectedPage);
  }
};

react-router-primitives's People

Contributors

dependabot[bot] avatar macintoshhelper avatar

Stargazers

 avatar

Watchers

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