next-routes
next-routes copied to clipboard
Adding meta data to route definition
I am piggybacking off of iherem's PR found here: #152
His PR notes below:
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 decreased (-0.2%) to 94.583% when pulling 9850a4d01fee5225f8de47658d51e2d31529e0e1 on nkramaric:feature/pr-meta-data into 08e8bbeaa76c5ec194abea388a193bedac7f35fc on fridays:master.
Please merge this, we need meta data in routes as well