Reaouter (not publish yet)

is a modern react routing library that is delightfully made with hooks. It is so clean to use and easy and understand because it has few imports with few properties in each. Even though it is few imports with few properties in each, yet it is powerful and smarter, which can be use in all environment, and even in scaled without head scratcher. one of it's significant feature is the SubRouter, it is use to reduce paths matching in vast environment which can be helpful to your app performances.

there is a bit bug in router and subrouter timeout for isNoMatch maybe use requestIdleCallback is the solution

Installation #

npm i reaouter
Imports #

import {
Router,
Link,
Route,
SubRouter,
RouteNotFound,
Redirect,
useLocation,
useParam,
useHistory
} from "reaouter";

API

Router #

It will makes your react pages dynamic.

Property
Property
Type
Type
Default
Default
Description
Description
scrollRestoration"auto" | "manual"autoThe scrollRestoration property of History interface allows web applications to explicitly set default scroll restoration behavior on history navigation.
auto - The location on the page to which the user has scrolled will be restored.
manual - The location on the page is not restored. The user will have to scroll to the location manually.
legacybooleanfalsethe hash routing will be applied.
childrenelement-A children element to render.
Route #

It is responsible to render some UI or component when its path matches the current url.

Property
Property
Type
Type
Default
Default
Description
Description
renderelement-A children element to render when path is matched.
pathstring-The route path whenever the current url matched then, the element you put in render property will be shown or rendered.
nestedbooleanfalseWhen it is true, then the router will know that this is not a real route end point. so when it is matched, it will move on to the decendant routes find the real route end point. but if there has no decendant route that has matched then it is still counted as no matched
exactbooleantrueWhen it is true, then it will only match if the path model is precisely matched to the current url and even the path is just a nested path. It will be matched if the certain part is exactly matched.
immutablebooleanfalseWhen it is true, then the page scroll will not move to top to reset. It is use when making a tabs, open a modals or show anything using SubRouter as midiator. as long you put property exact to false so it will allow routes inside it.
RouteNotFound #

It is responsible whenever there is no matched on all the routes.

Property
Property
Type
Type
Default
Default
Description
Description
renderelement-A children element will be rendered immidiately whenever there is no matched in all the routes.
SubRouter #

It will act as a nested route and a router at the same time. It is very effective when the app does have a lot of nested routes because whenever you are navigating to its territory, it will not bother the main router to checked all the routes unless the current url is outside its nested domain. But if the url doesn't matched, and it is under it's nested domain then, you need to handle your own RouteNotFound inside it.

Property
Property
Type
Type
Default
Default
Description
Description
renderelement-A children element to render when path is matched.
pathstring-The route path whenever the current url matched then, the element in render property is will be rendered.
Redirect #

Property
Property
Type
Type
Default
Default
Description
Description
pathstring-The route path when ever the current url matched it. then, it will be redirect to.
tostring-The url where this redirect will lead you to certain path when matched.
allowReturnBackbooleanfalseWhen true, it will allow you to turn back to the previous url before redirect.

Hooks

useLocation #

It is use to get the nested routes url and path to be a reference to its children routes and links.

Property
Property
Type
Type
Default
Default
Description
Description
const {
url,string-It is the sliced URL, based on the path of route you are under with.
path,string-It is the path of the route you are under with.
search,string-It is use to get url parameters.
hash,string-It is use to get url hash.
pathnamestring-It is the current URL which is complete without slice.
} = useLocation()
useHistory #

It is use to back from previous url, forward to url that once backed, and redirect to another url beside Redirect Component, but its use is outside the JSX.

Property
Property
Type
Type
Default
Default
Description
Description
const {
url,string-It is current url
stateobject{}it will get the state that has been attached alongside the URL
} = useHistory()
useParams #

It is use to get the parameters (you declared in path) in a form of key value pair.

/*http://localhost/branch/1/5/add*/
const Branch = () => {
const { param_one, param_two } = useParams()
return <div>{`Do the rest: ${param_one}`}</div>
}
<Route path="/branch/:param_one/:param_two/add" render={<Branch />} />

You cannot use it, unless you are under the Route component.

Warning!

In this pre-deployed stage, most of the library you will witness has yet been publish or update in npm.