1.2.14 • Published 10 months ago

stupid-react-router v1.2.14

Weekly downloads
-
License
UNLICENSE
Repository
github
Last release
10 months ago

Simple React Router

This is simple working react router.

Installation

Install stupid-react-router with npm

  npm install stupid-react-router

Add to your main component SetRefresher

import React from "react"
import { SetRefresher } from 'stupid-react-router'

function App(){
  const [state, setState] = React.useState(false); // Naming convention is up to you

  return (<React.Fragment>
    <SetRefresher state={state} setState={setState}>
    {/* your code ... */}
  </React.Fragment>);
}

export default App;

Usage/Examples

Route

Show children when path is correct

import { Route } from 'stupid-react-router'

function App() {
  return (<Route path="/path">
    show on /path/+
    <Route path="/exact" exact>
        show on /path/exact
    </Route>

    <Route path="/:user/edit" exact
        values={[':user']}
        setValues={(paths) => {
          console.log(paths); // ["anything"]
        }}>
        show on /path/anything/edit
    </Route>
  </Route>);
}

Switch

Show only first correct Route

import { Switch, Route } from 'stupid-react-router'

function App() {
  return (<Switch>
    <Route path="/path">show on /path/+</Route>
    <Route path="/">show on not /path/+</Route>
  </Switch>);
}

Link

Redirects on click to desired path

import { Link } from 'stupid-react-router'

function App() {
  return (<Link to="/">link</Link>);
}

redirect

redirects to desired path as not component

import { redirect } from 'stupid-react-router'

function App() {
  const handle = ()=>{
    redirect('/path');
  }

  return (<div>
  </div>);
}

Redirect

redirects on show to desired path

import { Switch, Route, Redirect } from 'stupid-react-router'

function App() {
  const handle = ()=>{
    redirect('/path');
  }

  return (<Switch>
    <Route path="/path">path</Route>
    <Route><Redirect to="/path"/></Route>
  </Switch>);
}

GetPath

returns path to callback

import { Route, GetPath } from 'stupid-react-router'

function App() {

  return (<Route path="/route">
    <GetPath callback={(path)=>{
        console.log(path); // ''
    }}/>
    <GetPath relative={false} callback={(path)=>{
        console.log(path); // '/route'
    }}/>
  </Route>);
}

Deployment

For deployment of this router you can use

Web server like apache2\ Hosting platform

Or just use serve

  npm run build
  serve -s build

License

THE UNLICESE © ogiusek

1.2.14

10 months ago

1.2.13

10 months ago

1.2.12

10 months ago

1.2.11

10 months ago

1.2.10

10 months ago

1.2.9

10 months ago

1.2.8

10 months ago

1.2.7

10 months ago

1.2.6

10 months ago

1.2.5

10 months ago

1.2.4

10 months ago

1.2.3

10 months ago

1.2.2

10 months ago

1.2.1

10 months ago

1.2.0

10 months ago

1.1.2

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.20

11 months ago

1.0.19

11 months ago

1.0.18

11 months ago

1.0.17

11 months ago

1.0.16

11 months ago

1.0.15

11 months ago

1.0.14

11 months ago

1.0.13

11 months ago

1.0.12

11 months ago

1.0.11

11 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago