![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
A small efficient framework-agnostic client-side routing library, written in TypeScript.
A small efficient framework-agnostic client-side routing library, written in TypeScript.
It is currently under development and API might slightly change.
Those features may be the ones you are looking for.
Esroute is written with no external dependencies, so it does not require you to use a library.
A configuration can look as simple as this:
import { createRouter } from "esroute";
const router = createRouter({
"": ({ go }, next) => next ?? go("/foo"),
foo: () => load("routes/foo.html"),
nested: {
"": load("routes/nested/index.html"),
"*": ({ params: [param] }) => load("routes/nested/dynamic.html", param),
},
});
router.onResolve(({ value }) => render(value));
You can compose the configuration as you like, which allows you to easily modularize you route configuration:
const router = createRouter({
"": ({ go }) => go("/mod1"),
mod1: mod1Routes,
merged: {
...mod2Routes,
...mod3Routes,
},
});
The router can be restricted to allow only certain resolution types.
const router = createRouter<string>({
"": () => "some nice value",
async: loadString(),
weird: () => 42, // TS Error
});
esroute comes with no dependencies and is quite small.
The route resolution is done by traversing the route spec tree and this algorithm is based on simple string comparisons (no regex matching).
When route resolution is done, all virtual routes (""
) on the path to the leaf are collected and then rendered from leaf to root.
This allows creating various szenarios. Here are some examples:
const router = createRouter({
members: {
"": ({ go }, next) => loggedIn ? next : go("/login")
...memberRoutes
}
});
In the example above, a logged in user will see the profile and a logged-out user will see the login page instead.
const router = createRouter({
foo: {
"": ({}, next) => (next ? `foo${next}` : "foo"),
bar: () => `bar`,
},
});
In this case the route /foo
will resolve to "foo"
and the route /foo/bar
will resolve to foobar
. With this pattern you can implement index routes and frames.
In some cases you might want to attach rendering af a common frame or a guard to a set of routes without placing them on a separate named parent route. This is where virtual routes come into play:
const router = createRouter({
"": {
"": ({ go }, value) => (loggedIn ? value ?? renderIndex() : go("/login")),
...memberRoutes,
},
login: () => renderLogin(),
});
In this sczenario we have the memberRoutes
next to the /login
route.
The Router
constructor takes two arguments: A Routes
and a RouterConf
object.
Routes
Example:
const routes: Routes = {
"": ({ go }, value) => (isLoggedIn || value) ?? go(["login"]),
x: resolveX,
nested: {
"": resolveNestedIndex,
y: resolveY,
level2: {
z: resolveZ,
},
"*": {
foo: ({ params: [myParam] }) => resolveFoo(myParam),
},
},
};
RouterConf
RouterConf
provides some router-specific configuration:
interface RouterConf<T> {
notFound?: Resolve<T>;
noClick?: boolean;
defer?: boolean;
onResolve?: (resolved: Resolved<T>) => void;
}
RouterConf.notFound
A fallback resolve funuction to use, if a route could not be found.
By default it redirects to the root path '/'.
RouterConf.noClick
Whether the click handler for anchor elements shall not be installed. This might make sense, if you want to take more control over how anchor clicks are handled.
RouterConf.defer
Whether the router should delay initialization until start()
is called on the Router
instance.
This can be used to prevent circular dependencies in your application. You can modify the routes
property on the router instance before calling start()
.
RouterConf.onResolve
A callback that is invoked whenever a route is resolved.
FAQs
A small efficient framework-agnostic client-side routing library, written in TypeScript.
The npm package esroute receives a total of 2 weekly downloads. As such, esroute popularity was classified as not popular.
We found that esroute demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.