frontarm/navi

Dynamic routes

DB-Alex opened this issue · 3 comments

Hi,

I want to build a new app but the data is coming from the wordpress api, including a large part of the routes.

Is this passible in navi?

It should be possible. There are a few ways go go about this:

  • You can use a map() that maps the request to a dynamically generated mount()
  • You can use route parameters, and fetch the content within an async map()

I don't have any familiarity with the wordpress API, but I'm pretty sure it should be possible to do what you want.

Can you provide 2 little examples? Its not clear to me

Ah i get the idea!

map(async () => {
        let rewrites = await firestore.collection(`rewrites`).get();
        let paths = {};

        rewrites.forEach((rewrite) => {
            let rewriteData = rewrite.data();

            if (rewriteData.type === 'page') {
                paths[rewriteData.path] = lazy(() => import('pages/ComponentsPage'));
            }
        });
        
        return mount(paths);
    }),