1.2.14 • Published 2 years ago

stupid-react-router v1.2.14

Weekly downloads
-
License
UNLICENSE
Repository
github
Last release
2 years 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

2 years ago

1.2.13

2 years ago

1.2.12

2 years ago

1.2.11

2 years ago

1.2.10

2 years ago

1.2.9

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago