Hi everybody!
Lately I found myself building my side projects with Frontity, even though they are not WP projects, because Frontity includes all the tech I want to use without having to wire anything (react-easy-state, emotion…).
One of the problems I run into is that the current @frontity/tiny-router
package is dependent on having a source package. It might be that you don’t even have a back end, but still need to do some routing, so I just created a small package to cover my needs and I am publishing it here in case somebody else wants to use it.
The package is just a clone of @frontity/tiny-router
removing the parts that are used with the source package and some features that didn’t seem relevant here (but if needed by anybody in the future they can be included).
I also cloned the Link
component from @frontity/components
with the needed modifications and simplifications to be used with this router.
Also, this was a quick adaptation and though I checked that it worked properly, it has no tests and it might contain bugs If you use it and run into any trouble, let me know.
Anyway, here it goes:
Info
Name: @orballo/very-tiny-router
NPM: @orballo/very-tiny-router - npm
Github: GitHub - orballo/very-tiny-router: A very tiny router (source agnostic) for Frontity
Install
npm i @orballo/very-tiny-router
Usage
Router action
const Button = () => {
const { actions } = useConnect();
const handleClick = () => {
actions.router.set("/");
};
return <button onClick={handleClick}>Go Home</button>;
};
Link component
import Link from "@orballo/very-tiny-router/link";
const Component = () => {
return <Link link="/">Go Home</Link>;
};
If somebody finds it useful and needs some further explanation, don’t hesitate to ping me here and I’ll gladly help.