add metadata to route
When I can't specify additional values and send them to custom handlers. Then I add the metadata into the constuctor to specify the value of what will be added to the custom handler.
Suppose I want to specify the locale of route
routes.add({ name: 'home', pattern: '/home', page: 'home', metadata: { locale: 'en' } })
The custom handlers receive the metadata
const handler = routes.getRequestHandler(app, ({ req, res, route, query }) => {
const { metadata: { locale }, page } = route;
renderWithCache(req, res, page, locale, query);
});
and the simple case if you want to specify some of route for cache just add the { cache: true } in the metadata
reference issue #127
Coverage increased (+0.08%) to 96.186% when pulling 8f434b0d28519bc83529343e5b62f839a8d4b979 on iherem:master into 4630d1961dbf65772fc957bb36a38cbfcb072318 on fridays:master.
Naive question perhaps, but why can’t the locale be part of the pattern?
Actually, I used it with my silly case. I don't know how other people do. for example: I have the base route /landing if i go straight to url /uk/landing or /ph/landing the content is changing depend on the route country. but the metadata can be everything you want to send to the server
but the metadata can be everything you want to send to the server
What part is sending stuff to the server? I'm a little confused 🙂
Also, you should update documentation to reflect these changes, and bump the library minor version according to https://semver.org/.