-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't have pages with children render correctly: routes: { page: ':link', #19
Comments
Just me that wants to render pages and child pages with correct routes matching WordPress permalinks so WordPress users can use the CMS headless without restriction? I'm going to read up on how this add node thing works and see if I can split up the WordPress link attribute that's delivers things like '/sections/about-us/corporate-info/annual-report/' and see if I can make routes for each one dynamically. |
I feel like this is the answer but I don't understand the documentations context, like where I would put my modified version of the code- in the plugins array? |
I have been able to successfully build page and there routes without the wordpress starter, Check it: //gridesome.server.js module.exports = function (api) {
}) |
Hi there @Kainkainkain , I got this working fine with:
So
The main difference here is the homepage is in Gridsome, other pages aren't. |
@daviddarke and did this handle page parents and page depth? e.g. |
@Kainkainkain That is a very point. I see from your initial post that was a goal. 🤔 @hjvedvik Are you looking into hierarchical post types? I assume to keep the WP-API fields clean and intact, it would make sense to add a new 'hierarchy-link' (or whatever) field to the GraphQL store. This could be as simple as the permalink with the base URL removed right? I would love to know your thoughts on this. |
I'm hoping to achieve this as well. It would be nice to have paths reflect the URL structure already defined in WordPress where possible. I think your interpretation is correct, @daviddarke, those would seem to be the options.
In any case, the new field would have a value equivalent to I have attempted achieving the first option through Gridsome plugins and transformers, but haven't had any success. Due to my lack of experience with Gridsome, currently the second option is looking more viable. However, it would still be good to know if this can indeed be achieved in Gridsome. |
I have since attempted implementing this through WordPress, so just sharing my findings. A
Node fields can be used as path parameters.
Path parameters are slugified by default.
Original values can be used by adding a
Special characters in original values seem to be encoded.
Unfortunately, modifying WordPress REST API responses gets pretty close, but does not seem to be a viable workaround. Ideally, template paths could be defined programmatically when using source plugins, similar to Alternatively, it would be good to know how to add a field to GraphQL when using source plugins. |
I should have shared the solution i worked out:
|
Hi @ramiroazar I attempted to follow the discussion in the linked feature request and I cannot work out how to apply it to the situation @Kainkainkain described in the original post in this thread. It seems that it is possible to obtain the parent slug? I have the following code in my Gridsome.config.js templates block:
But on \0\page_with_id_22 Which is if you squint nearly what I need, but doesn't quite get there. Any suggestions? |
Instead of using a string with parameters in the template
|
Doesn't work.
routes: { page: ':link_raw', }
is close - but the / character comes out as URL decoded %2f.
E.g. all the links are:
mysite.com/toppage%2fsecondlevel%2fthirdlevel
So can only have /pages/:slug which is not SEO or structured (especially for 3-4 level deep websites).
Goal would be able to replicate wordpress page structure
The text was updated successfully, but these errors were encountered: