Skip to content

add ufbr addon #1372

Closed
zakarialaoui10 wants to merge 2 commits intopreactjs:masterfrom
zakaria-forks:master
Closed

add ufbr addon #1372
zakarialaoui10 wants to merge 2 commits intopreactjs:masterfrom
zakaria-forks:master

Conversation

@zakarialaoui10
Copy link
Contributor

@zakarialaoui10 zakarialaoui10 commented Jan 26, 2026

Overview

ufbr is an Universal File Based Router with Preact supports

Features

  • File Based Routing
  • Static and Dynamic Routes
  • Dyamic routes
  • Supports Fragement components

Demo

Open in StackBlitz

Usage

// .src/main.jsx
import { createFileBasedRouter } from "ufbr/preact";
createFileBasedRouter(
    {
        pages : import.meta.glob('./pages/**/*.jsx'),
        target : document.getElementById('app'),
    }
)
//  .src/pages/slug/[...slug].jsx
export default function Pags({ slug }) {
    const items = slug.split('/');
    return (
        <ul>
            {items.map((item, index) => (
                <li key={index}>{item}</li>
            ))}
        </ul>
    );
}

This setup supports the following routes:

  • /slug/a
  • /slug/a/b
  • /slug/a/b/c
  • and any deeper nested paths.

Best practices

Use ufbr with Preact when you need a client-side, file-based router and SEO is not a priority (for example, dashboards or internal tools).
For SSR and SEO-focused, file-based routing, consider using Next.js, Astro, or similar frameworks.

Implementation :

https://github.com/zakarialaoui10/ufbr/blob/main/src/preact/index.js

Copy link
Member

@rschristian rschristian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a skim, but this doesn't seem to really be a Preact library, as you're consuming things that look like Preact components (but aren't) into a wrapper.

This isn't a file-based router that'd work for Preact apps, but your own framework. I don't think it's appropriate here

@zakarialaoui10
Copy link
Contributor Author

I took a skim, but this doesn't seem to really be a Preact library, as you're consuming things that look like Preact components (but aren't) into a wrapper.

This isn't a file-based router that'd work for Preact apps, but your own framework. I don't think it's appropriate here

You can check the demo
I have already added this note

Ufbr takes zikojs file based router which can be customized by a domifier
zikofy/preact export both zikofy and domify
domify tranform preact component to HTMLElement

@zakarialaoui10
Copy link
Contributor Author

I took a skim, but this doesn't seem to really be a Preact library, as you're consuming things that look like Preact components (but aren't) into a wrapper.

This isn't a file-based router that'd work for Preact apps, but your own framework. I don't think it's appropriate here

This how it works

Screenshot_20260126_224353_GitHub.jpg

It doesn't transform Preact to Zikojs
Just i used an util without reimplement it

@rschristian
Copy link
Member

Yes, I had checked the demo, but those aren't Preact components being used as they can be async. That's very much not allowed.

This page should generally be about tools you can use in a Preact app, not tools that can take Preact-ish components for use elsewhere.

@zakarialaoui10
Copy link
Contributor Author

Maybe something is wrong because i misunderstood how Preact works , i will solve it later with other approach

@zakarialaoui10
Copy link
Contributor Author

@rschristian

I reimplemented it.

I’m no longer using the ZikoJS file-based router itself, only a few shared utilities for route matching and dynamic params (masks, checks, parsers, etc.).

With this approach, async function App() is not allowed.
If a component needs to perform async work, it should do so inside a useEffect hook instead, following Preact’s rendering rules.

The new Demo : https://stackblitz.com/edit/zakarialaoui10-ufbr-uggmzzzd?file=src%2Fpages%2Fasync%2Ftodos%2F[id].jsx
The new Implementation : https://github.com/zakarialaoui10/ufbr/blob/main/src/preact/index.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants