Pages other than the current page are difficult to access #3093
Replies: 2 comments 6 replies
-
Why not
Same: why not The more I know about your use concrete use cases, the better. |
Beta Was this translation helpful? Give feedback.
-
|
It would cause a new render and thus would break the example. It would be possible to work around this, but that would be more complicated than using a component outside of the page or using the private methods to get the page.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
The page system is the main way to define the routes and there doesn't seem to way to define base routes outside of the filesystem, see issue. This creates a situation where the page is difficult to reuse without moving data outside of the page. Although that is acceptable this disconnects the data (html / component / metadata) from the page and routing. This means that there is no guarantee that the data is actually connected to the route and Vike route information / hooks is difficult to wire together. I don't think this is a major problem, but I think there should be public methods to access page data other than the current page or to be able to register routes programmatically. Programatically defining routes by default solves this issue as then the data can be connected routes in user land and is thus available via normal means. There should be some method to have the route information associated with the page as well.
This can already done by accessing private properties in the context, namely
context._pageConfigs. I think there's also some plugins usingvike/__internalsto access this data. I think these should just be made public and more clearly accessible instead of the current data:const pageEntry = pageConfig.loadVirtualFilePageEntry().moduleExportsPromiseconst page = pageEntry.configValuesSerialized.Page.valueSerialized.exportValues.defaultConcrete examples:
User attempts to load an product page, but something in the page goes wrong and cannot be recovered. I would like to be access the error page.
User wants to log in a page that has persistent data, I would like to show the component from the login page in a dialog.
Beta Was this translation helpful? Give feedback.
All reactions