Define routes for nodes in one place
See original GitHub issueMove route options for all content types into a routes
(or any better name) section in gridsome.config.js
. Currently, each source plugin implements routes on their own. But after this change, source plugins doesn’t need to worry about routing etc. We also believe it will give a better overview having all node routes in one place. And it will be easier to extend the functionality later. Content types not defined there will not be generated or have a path
field in the GraphQL schema.
The routes
config will be config for how pages for nodes should be generated. This is not a breaking change, but the route
option for content types will be deprecated.
So instead of defining a route
for the source or a content type like this:
{
use: '@gridsome/source-filesystem',
options: {
typeName: 'User',
route: '/user/:name'
}
}
Define the route in routes
like this:
module.exports = {
routes: {
User: '/user/:name' // typeName: route
}
}
Here is how the full config might look like:
module.exports = {
routes: {
// simple config
Post: '/:year/:month/:day/:slug',
// specify component
Post: {
path: '/:year/:month/:day/:slug',
component: './src/templates/CustomPostTemplate.vue'
},
// all possible options
Post, {
path: '/:year/:month/:day/:slug',
component: './src/templates/Post.vue',
dynamicRoute: false, // generate one route for each node
fieldName: 'path' // graphql field name
},
// generate multiple templates for content type
Author: [
{
path: '/author/:name',
component: './src/templates/Author.vue'
},
{
path: '/author/:name/books',
component: './src/templates/AuthorBooks.vue',
fieldName: 'booksPath'
}
]
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:27
- Comments:7 (4 by maintainers)
I think
pages/[id].vue
looks much better @Atinux 😃 We’ll consider the same for the same reasons.@Al-Rozhkov Nested routes and named views could be interesting. I’m not sure how to implement it with automatic generation and GraphQL etc atm, but will definitely take a look at it sometime.
@Al-Rozhkov 0.7 will have client-side route support. We’re thinking about doing it like Nuxt does. Where you add for example a
user/_id.vue
file to get auser/:id
route + an option to do it programmatically.