How to use the wouter-preact/matcher function in wouter-preact

To help you get started, we’ve selected a few wouter-preact examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kidqueb / preact-polka-ssr / src / server / _getCurrentRoute.js View on Github external
import makeMatcher from "wouter-preact/matcher";

import routes from "../routes";
const matcher = makeMatcher();

/**
 * Find out what route should be displayed and return it along 
 * with the parsed parameters from the route's path pattern.
 * @param {object} req - polka's request object
 */
export default async req => {
	let CurrentRoute, routeParams, route;

	for (let index = 0; index < routes.length; index++) {
		route = routes[index];

		// Find out if the route matches the url.
		const [matches, params] = matcher(route.path, req.url);

		// Move on if it's determined to not be the current route.

wouter-preact

Minimalist-friendly ~1.5KB router for Preact

Unlicense
Latest version published 14 days ago

Package Health Score

80 / 100
Full package analysis