This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

corniche

0.1.0-alpha.1 • Public • Published

Router

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.

Readme

Keywords

none

Package Sidebar

Install

npm i corniche

Weekly Downloads

2

Version

0.1.0-alpha.1

License

none

Unpacked Size

12.5 kB

Total Files

18

Last publish

Collaborators

  • robbdimitrov