Skip to content
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

Adding meta for routes without a component #33

Open
posva opened this issue Jul 12, 2022 · 3 comments
Open

Adding meta for routes without a component #33

posva opened this issue Jul 12, 2022 · 3 comments
Labels
⚡️ enhancement improvement over an existing feature

Comments

@posva
Copy link
Owner

posva commented Jul 12, 2022

Creating folders create routes and any file inside them becomes a nested route. This wasn't possible before v4.1 but now it makes sense to allow defining meta properties (mainly but also any other route property) at this level

This could maybe be achieved with a special file users/__route.js that exports some properties like name, meta, etc (the same as in the <route> block)

@Soviut
Copy link
Sponsor

Soviut commented Jul 21, 2023

This would be nice for applying meta: { requiresAuth: true } to a parent route. Currently, I'm having to use definePage on every child page.

@jods4
Copy link

jods4 commented Jan 8, 2024

Here we're building our navigation menus from the routes table (using metadata added in route blocks).
We'd like to add metadata to the non-navigable parent nodes, too.

We used the following hack to work-around this:

  1. Create an empty index.vue page anyway, with a <route> block and metadata.
  2. In the metadata, include a marker that the page must be removed, e.g. "remove": true.
  3. We use the extendRoute(route) callback during build to customize the process a bit:
if (route.node.value.overrides?.remove)
{
  // Move metadata to parent, depends on your use cases
  route.parent.addToMeta(route.node.value.overrides.meta);
  // Remove from routing table
  route.delete();
}

If anyone's interested, that approach works.
It would be nice to have this built-in though, maybe as the default export of __route.js as suggested initially; or __route.json and __route.yaml for syntax consistency with <route> blocks.

Random remark: route.node is described as a private variable in code, yet there is no access to overrides object from EditableTreeNode. I feel like one public API is missing?

@posva
Copy link
Owner Author

posva commented Jan 8, 2024

Thanks for sharing your approach!
I'm realizing this is quite old now and I haven't implemented any experimental APIs around it yet... I hope to get back to it after #246 and the Data Loaders RFC

Random remark: route.node is described as a private variable in code, yet there is no access to overrides object from EditableTreeNode. I feel like one public API is missing?

Yes, EditableTreeNode is definitely still missing some APIs but also docs and examples 😅

@settings settings bot removed the enhancement label Feb 21, 2024
@posva posva added the ⚡️ enhancement improvement over an existing feature label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡️ enhancement improvement over an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants