Hi,
Iām really interested in using Frontity to build a new front, but the site is heavily customized with lots of rewrites, filters etc, so there are a few kinks I need to make sure that I can work out before I can get started on a theme.
Iāve been trying to add a custom path pattern, but I have run in to some issues and I canāt seem to find my answer in the documentation.
I used the example from the documentation and edited it to fit my purpose:
init: ({ libraries }) => {
libraries.source.handlers.push({
name: "country-info",
priority: 1,
pattern: "/:slug",
func: async ({ route, params, state, libraries, force }) => {
const response = await libraries.source.api.get({
endpoint: "country-info",
params: { slug: params.slug },
});
const [countryInfo] = await libraries.source.populate({
response,
state,
force,
});
Object.assign(state.source.data[route], {
id: countryInfo.id,
type: countryInfo.type,
isPostType: true,
isCountryInfo: true,
});
},
});
},
The handler works fine when the slug matches an existing post, but when I enter a non-existing slug I get this Error:
TypeError: Cannot read property 'id' of undefined
at Object.func (webpack-internal:///./packages/mars-theme/src/index.js:14:558)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:182:7)
And the site only displays āInternal Server Errorā.
So hereās what Iād like to know:
-
What would you recommend that I check for in the response to see if a post was found or not?
-
If no posts where found, what should I do to generate a proper 404 error and make the 404 page show up?
-
Letās say I get a result that I for some reason want to ignore on the front end, how can I make Frontity move on and try to match the next pattern in the priority chain? (As if the pattern didnāt match)
Also, thank you for making this framework. I love working with WordPress and I love working with React. I have often used React apps in websites I built in WordPress, but your framework is exactly what I have been looking for! Keep up the good work!
Fred