next-routes icon indicating copy to clipboard operation
next-routes copied to clipboard

Adding meta data to route definition

Open nkramaric opened this issue 5 years ago • 2 comments

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

nkramaric avatar Nov 15 '19 16:11 nkramaric

Coverage Status

Coverage decreased (-0.2%) to 94.583% when pulling 9850a4d01fee5225f8de47658d51e2d31529e0e1 on nkramaric:feature/pr-meta-data into 08e8bbeaa76c5ec194abea388a193bedac7f35fc on fridays:master.

coveralls avatar Nov 17 '19 17:11 coveralls

Please merge this, we need meta data in routes as well

subhajeet2107 avatar Feb 28 '21 06:02 subhajeet2107