-
Notifications
You must be signed in to change notification settings - Fork 27
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
[Feature Request] Name Views Support #265
Comments
Worked arround it by using a little function to parse the routes I got - all routes started with an function parseRoutes(routes: Array<RouteConfig>) {
return routes.map((route: RouteConfig) => {
if ((route?.children?.length ?? 0) > 0) {
const views = route?.children?.filter((child: RouteConfig) =>
child.name?.startsWith("@")
);
route.children = parseRoutes(
route.children?.filter(
(child: RouteConfig) => !child.name?.startsWith("@")
) ?? []
);
if ((views?.length ?? 0) > 0) {
const singleViewRoute = route as RouteConfigSingleView;
const defaultComponent = singleViewRoute.component;
const defaultProps = singleViewRoute.component;
const multiViewRoute = route as RouteConfigMultipleViews;
if (defaultComponent !== null && defaultComponent !== undefined) {
const components: Dictionary<Component> = {
default: defaultComponent,
};
views?.forEach((view: RouteConfig) => {
const singleViewView = view as RouteConfigSingleView;
if (
singleViewView.component !== null &&
singleViewView.component !== undefined
) {
components[view.name?.substring(1) ?? view.path] =
singleViewView.component;
}
});
multiViewRoute.components = components;
}
if (defaultProps !== null && defaultProps !== undefined) {
// eslint-disable-next-line @typescript-eslint/ban-types
const props: Dictionary<boolean | Object | RoutePropsFunction> = {
default: defaultProps,
};
views?.forEach((view: RouteConfig) => {
const singleViewView = view as RouteConfigSingleView;
if (
singleViewView.props !== null &&
singleViewView.props !== undefined
) {
props[view.name?.substring(1) ?? view.path] =
singleViewView.props;
}
});
multiViewRoute.props = props;
}
return multiViewRoute;
}
}
return route;
});
} |
What is the use case for that with vue-route-generator? |
When using Simply said, you can think of enough use cased but there seems to be no supported way of setting named views from files - except reparsing the generated routes on every application startup (an option would be to have a callback in the loader itself, so after generation of the routes so one can change stuff) |
Like the title says, it would be cool if we could use named views with this plugin like shown here:
https://router.vuejs.org/guide/essentials/named-views.html
This would open up so many more possibilities 😲
The text was updated successfully, but these errors were encountered: