0.1.2 • Published 4 years ago

react-router-primitives v0.1.2

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

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

PropTypeDefaultNote
locationstring | LocationrequiredString or Location e.g. { key: 'ac3df4', pathname: '/somewhere', search: '?some=search-string', hash: '#howdy', state: [userDefined]: true } }
locations[string[]] | [Location[]]requiredList of strings or locations
viewportviewportrequiredObject: { name: string, width: number, height: number}
childrenNoderequired

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);
  }
};
0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

1.0.0

4 years ago