Dynamic routes
DB-Alex opened this issue · 3 comments
DB-Alex commented
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?
jamesknelson commented
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 generatedmount()
- 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.
DB-Alex commented
Can you provide 2 little examples? Its not clear to me
DB-Alex commented
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);
}),