
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
router-preact
Advanced tools
A tiny router for Preact apps. It connects your app with the address bar. That's it.
npm install --save router-preact
Yarn users, you know what to do instead.
The following examples are written in JSX format, for brevity.
import { Link, Route } from 'router-preact';
const App = () => <>
<Route path="/">
<Link to="/next">Next page</Link>
</Route>
<Route path="/next">
<Link to="/">First page</Link>
</Route>
</>;
import { Link, Route, pattern } from 'router-preact';
const App = () => <>
<Route path="/">
<Link to="/pages/1">Go to page 1</Link>
</Route>
<Route path={pattern`/pages/${'pageNumber'}`} render={({ params: { pageNumber } }) => <>
<p>Thank you for visiting page {pageNumber}.</p>
<Link to={`/pages/${pageNumber + 1}`}>Go to next page</Link>
</>}/>
</>;
import { Redirect, Route } from 'router-preact';
const App = () => <>
<Route path="/">
<Redirect to="/pages/1"/>
</Route>
</>;
If you really want to, you can swap out the router implementation by
using the Router
context provided by this package. For example, if
you want to test a component that involves routing.
import { Router } from 'router-preact';
const myRouter = {
match(path) {
// If the given path matches the currently active route, then return an object with key-value pairs for each path parameter
// Otherwise, return `undefined`
},
navigate(path) {
// Transition the currently active route to the given path and notify any callbacks registered via onNavigate() of the new path
},
onNavigate: (callback) => () => {
// Register the callback so that it gets notified when the active route changes
// Return a function that, when called, will deregister the callback
},
path() {
// Return the path of the currently active route
},
query() {
// Return the query parameters of the currently active route as an object
}
};
const App = () => <Router.Provider value={myRouter}>
...
</>;
FAQs
Tiny router for Preact apps.
The npm package router-preact receives a total of 1 weekly downloads. As such, router-preact popularity was classified as not popular.
We found that router-preact demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.