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

Unified custom route data #557

Open
3 tasks done
Cubxx opened this issue Sep 17, 2024 · 2 comments
Open
3 tasks done

Unified custom route data #557

Cubxx opened this issue Sep 17, 2024 · 2 comments

Comments

@Cubxx
Copy link

Cubxx commented Sep 17, 2024

Description

SFC custom block and JSX/TSX YAML format comments are not perfect method to custom route data, especially when I want to use imported data in route data:

import { mdiHomeOutline } from '@mdi/js';
const route = {
  meta: {
    btnProps: {
      tip: 'home',
      icon: mdiHomeOutline,
      order: 2,
      hideOn: 'mobile',
    },
  },
}

Suggested solution

custom route data in runtime code is maybe better method, it has natural framework-independence advantage, and support type check:

// src/pages/index.tsx
import type { RouteMeta } from 'vue-router';
import { mdiHomeOutline } from '@mdi/js';
export const route = {
  meta: {
    btnProps: {
      tip: 'home',
      icon: mdiHomeOutline,
      order: 2,
      hideOn: 'mobile',
    } satisfies RouteMeta,
  },
}
export default ...

Alternative

No response

Additional context

No response

Validations

  • Follow the Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@hannoeru
Copy link
Owner

hannoeru commented Sep 24, 2024

If I add too much support to this is kind of thing which is framework specific, will cause this plugin to become hard to maintain.
I personal will recommend using some existing solution like Remix to resolve that kind of requirement.

@Cubxx
Copy link
Author

Cubxx commented Sep 26, 2024

@hannoeru I don't think it is framework specific. Actually, merging custom data from page file with generated route from plugin in virtual module is feasible methods, which is what I do currently.

I used import.meta.glob to achieve it, just like:

// as a part of virtual module
const customs= import.meta.glob(
  ['~/pages/**/*.tsx', '!~/pages/**/components/*'],
  { import: 'route', eager: true },
);

of course, it will throw error when the page file don't export named route data, so we can add export route = {} to solve it on transform hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants