npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wompo-router

v1.3.4

Published

Wompo-Router allows to create a Single Page Application using Wompo.

Downloads

10

Readme

Wompo Router

Wompo-Router is a Wompo based library to create Single Page Applications using client routing. Wompo Router uses nested routes to create layouts, based on the famous React-Router library.

API

Wompo Router exposes the following components to create routes:

  • Routes - It's the component that will include the whole routing logic. Accepts a notFoundElement prop, which defines what to render when the router don't find a matching route, and an origin prop, which specifies the url location on where the routing starts.
  • Route - Define a single route. Accepts the following props:
    interface RouteProps extends WompoProps {
    	path?: string; // The path of the route.
    	index?: boolean; // True if the route is an index route (of the parent).
    	redirect?: string; // If valorized, the route will redirect to another one.
    	element?: RenderHtml; // The element to render.
    	lazy?: () => LazyCallbackResult; // If valorized, must be a callback that returns a lazy component.
    	fallback?: RenderHtml; // The fallback element to visualize while a lazy component is being imported.
    	meta?: {
    		title?: string;
    		description?: string;
    	};
    }
  • ChildRoute - Defines where a child route should be rendered inside the parent route. Accepts no props.

It also exposes this helper components:

  • Link - The component you want to use to navigate across routes. Accepts two props: to (the link), and target.
  • NavLink - Same as Link, but will have an "active" class if the current route corresponds to the link. Accepts a two props: to (the link), and target..

Finally, Wompo Router has the following hooks:

  • useParams - Will return the parameters for the current route.
  • useNavigate - Will return a navigate function that you can use to manually navigate across routes.
  • useCurrentRoute - Will return the current route.
  • useRoutes - Will return the array of routes that the router can handle.

Creating an Application

This is an example of an application made with Wompo Router:

function App() {
	return (
		<Routes>
			<Route path='/' element={<HomePage />} />
			<Route path='/docs' element={<DocsLayout />}>
				<Route path='overview' element={<Overview />} />
				<Route path='quick-start' element={<QuickStart />} />
				<Route path='hooks' element={<Hooks />}>
					<Route path=':name' element={<Hook />} />
				</Route>
				<Route index redirect='overview' />
			</Route>
			<Route path='*' element={<NotFound />} />
		</Routes>
	);
}

The above routing system will generate the following routes:

  • /
  • /docs ---> will redirect to ---> /docs/overview
  • /docs/overview
  • /docs/hooks
  • /docs/hooks/:name (where "name" is a parameter in the url)

All the other routes will fallback into the NotFound Page.

So, if you go to the url /docs/hooks/useNavigate, Womp Router will render the following nested routes where "useNavigate" is assigned to the "name" parameter:

<DocsLayout>
	<Hooks>
		<Hook />
	</Hooks>
</DocsLayout>

Actually, this process of nested routes will not happen automatically: the components DocsLayout and Hooks will have to tell "Womp Router" where to render the nested route. To do that, you use the ChildRoute component.

Example of DocsLayout:

<header>...</header>
<main>
  <ChildRoute />
</main>
<footer>...</footer>