@forgeframework/react-router
v0.3.0
Published
Type-safe routing library for Forge Framework web applications.
Downloads
533
Maintainers
Readme
@forgeframework/react-router
Type-safe routing library for Forge Framework web applications.
Part of the Forge Framework — a TypeScript framework for backend microservices and web applications.
Installation
npm install @forgeframework/react-routerUsage
import { ForgeRouter, Link, useNavigate, useParams } from '@forgeframework/react-router';
const router = ForgeRouter({
mode: 'browser',
routes: [
{
path: '/',
layout: AppLayout,
children: [
{ path: '', component: Home },
{
path: 'users',
guards: [new AuthGuard()],
children: [
{ path: '', component: UserList },
{ path: ':id', component: UserDetail, loader: loadUser },
],
},
],
},
],
notFound: NotFoundPage,
});
function UserDetail() {
const { id } = useParams<{ id: string }>();
const navigate = useNavigate();
const user = useLoaderData<User>();
return (
<div>
<h1>{user.name}</h1>
<button onClick={() => navigate.push('/users')}>Back</button>
</div>
);
}Documentation
Full API reference and guides: https://carbonforge.io/framework/docs/web/react-router
(Documentation site launching soon.)
License
MIT © Carbon Forge
