DreaMinder / nuxt-payload-extractor

Nuxt.js module that makes `nuxt generate` command to store html and payload separately.
MIT License
145 stars 18 forks source link

Provide all data available #7

Closed edimitchel closed 5 years ago

edimitchel commented 5 years ago

All data available for providing payload on nested routes

By this way, all payload are extracted for routes (nested too).

It works for my personal website.

DreaMinder commented 5 years ago

Interesting. If it wasn't working before your fix, can you describe, what was wrong? Parent route wasn't working on client-side navigation, am I right? And can you provide your nested routes structure?

What I found out is that nested routes generation doesn't work right, thanks to your help. In my implementation, only child-route has been extracting to payload.json, which is wrong for parent-route. But in your implementation only parent-route is extracting right data to payload.json (because .find returns first true value from array), which is wrong for child-route. In other words, with your approach, on client-side navigation to child-route, you should have payload.json with data of parent-route. With my approach it is another way around and still wrong.

To solve the issue, we need to get nesting-level of current route. Maybe I'll try to calculate it from route path. What do you think about this?

edimitchel commented 5 years ago

Interesting. If it wasn't working before your fix, can you describe, what was wrong? Parent route wasn't working on client-side navigation, am I right? And can you provide your nested routes structure? I have a nested route like : /_lang/blog/_slug and /_lang/blog/_slug/_page. The two last nested routes didn't get payload.json built properly (empty : { }).

I debug in local for looking the issue, and I found that data of the most nested route is a double array, with the last empty. The code takes always the last one.

What I found out is that nested routes generation doesn't work right, thanks to your help. In my implementation, only child-route has been extracting to payload.json, which is wrong for parent-route. But in your implementation only parent-route is extracting right data to payload.json (because .find returns first true value from array), which is wrong for child-route.

You're may be right.. I will check this. I've perhaps miss something..

In other words, with your approach, on client-side navigation to child-route, you should have payload.json with data of parent-route. With my approach it is another way around and still wrong. To solve the issue, we need to get nesting-level of current route. Maybe I'll try to calculate it from route path. What do you think about this?

I'll see this tomorrow ;)

Thanks for your reply !

DreaMinder commented 5 years ago

Cool, it works, but:

  1. it won't work if parent and child page route will have same field returned by asyncData
  2. this way parent and child route will get exact same json content (both child and parent content in one file) from 2 different endpoints. So there will be redundant data in JSON.

I'll think about it tomorrow, in case I'll have night dream about better implementation...