-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Support non absolute paths in EditableTreeNode
#341
Comments
Can you share a failing test case? |
In this situation, the routing table looks like: [
{
path: "/parent",
children: [
{ path: "child" }
]
}
] Doing a simple |
The warning is actually correct: currently, only absolute paths are supported. Ideally, setting the path should work with both absolute and non-absolute paths, but that hasn't been implemented yet. Contribution welcome! |
EditableTreeNode
@posva can you explain a little more where the problem lies? I don't get it. |
It’s because in the build-time hooks to change routes you don’t get access to the route records, you get access to an editable tree node that then gets serialized into a route tree. Therefore some operations are different |
ok. I suppose a work-around for the time being is building and assigning the full absolute path of the child route. With a bit of glue code it can be done (walk up the parents routes and merge them, being careful if they are relative or absolute). |
Yeah, it’s not intuitive. It will be improved sooner or later |
Just for context, I believe the issue comes from the differences between the meaning of path in different contexts. Here's an example in the https://github.com/posva/unplugin-vue-router/blob/main/src/core/tree.ts /**
* Returns the route path of the node without parent paths. If the path was overridden, it returns the override.
*/
get path() {
return (
this.value.overrides.path ??
(this.parent?.isRoot() ? '/' : '') + this.value.pathSegment
)
}
/**
* Returns the route path of the node including parent paths.
*/
get fullPath() {
return this.value.overrides.path ?? this.value.path
} You can see that the override is actually overriding the whole |
Just chiming in on this because I've reviewed our applications again. To provide context: what we'd like to do is simply force a kebab-case convention on URLs, although our folders could be PascalCase, and similar deviations. Just think Digging into the code again, maybe all we need is to manipulate Generally this seems to be a very inconsistent topic as:
In fact, when I look at the generated auto-routes file, I see this: {
path: 'news', /* <-- RELATIVE ALL THE WAY TO BROWSER! */
name: '/Admin/System/news',
component: () => import("/Modules/Admin/System/news.page.vue"),
/* no children */
meta: { /*...*/ }
} Hopefully if #519 can be merged this will be more flexible. |
Thanks for the feedback and the PRs (@robertmoura @jods4). This really helps to understand cases I didn't think about in the first place. I'm still a bit swamped with other stuff at the moment so I will come back to this later, hopefully in January and do a big pass with other HMR improvements and more data loaders API. |
I'm using
extendRoute
to normalize our paths (to camelcase, but our files and folders sometimes have different casing).Setting
route.path
sometimes incorrectly logs warnings "Only absolute paths are supported.".Offending code is here: https://github.com/posva/unplugin-vue-router/blob/main/src/core/extendRoutes.ts#L135
The oversight of this warning is that a route can be a nested child route, and
path
is only the local path, not the full one. In this instance a relative path is ok (common, even).The text was updated successfully, but these errors were encountered: