0.1.0-alpha.1 • Published 4 years ago
corniche v0.1.0-alpha.1
Corniche
Simple router for react without external dependencies.
Example usage:
Create routes:
const routes = [
{ path: '/home', component: Home },
{ path: '/users/:userId', component: Profile },
{ path: '/settings', component: Settings },
{ path: '/404', component: NotFound },
{ path: '/', redirectTo: '/home' },
{ path: '*', redirectTo: '/404' }
];
Init Router:
import Router from './router';
function App() {
return (
<Router routes={routes}>
<Navbar />
</Router>
);
}
Use the useRouter
hook to navigate and get path params
function Profile(props) {
const router = useRouter();
const handleClick = () => {
router.navigate('/settings');
};
return (
<div className="container">
<h1>Profile {router.params.userId}</h1>
<button type='button' onClick={handleClick}>
Open Settings
</button>
</div>
);
}
License
Licensed under the MIT License.
0.1.0-alpha.2
4 years ago
0.1.0-alpha.1
4 years ago