fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

add metadata to route #152

Closed iherem closed 1 year ago

iherem commented 6 years ago

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

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.08%) to 96.186% when pulling 8f434b0d28519bc83529343e5b62f839a8d4b979 on iherem:master into 4630d1961dbf65772fc957bb36a38cbfcb072318 on fridays:master.

trotzig commented 6 years ago

Naive question perhaps, but why can’t the locale be part of the pattern?

iherem commented 6 years ago

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

trotzig commented 6 years ago

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 🙂

thomasdom commented 5 years ago

Also, you should update documentation to reflect these changes, and bump the library minor version according to https://semver.org/.