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

extendRoute does not support JS #338

Closed
5 tasks done
blowsie opened this issue Nov 21, 2022 · 2 comments
Closed
5 tasks done

extendRoute does not support JS #338

blowsie opened this issue Nov 21, 2022 · 2 comments

Comments

@blowsie
Copy link

blowsie commented Nov 21, 2022

Describe the bug

Since yml and json5 don't allow us to write JS functions, I tried to extend a route using extendRoute, however that fails when writing functions too.

Config

  extendRoute(route) {
          if (route.meta && route.meta.props) {
            route.props = function () {
              return route.meta.props
            }
          }
          return route
        },

Output

const __pages_import_0__ = ()=>import("/src/pages/test.vue");

const routes = [{
    "name": "test",
    "path": "/test",
    "component": __pages_import_0__,
    "props": function() {
        returnroute.meta.props;
    },
    "meta": {
        "title": "Item",
        "props": ["item", "delivery", "timeline"]
    }
}];

export default routes;

Reproduction

https://stackblitz.com/edit/vitejs-vite-zwtdaf?file=vite.config.ts

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm

Used Package Manager

npm

Validations

  • Follow the Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A please open a GitHub Discussion.
  • The provided reproduction is a minimal reproducible example of the bug.
@blowsie blowsie mentioned this issue Nov 21, 2022
3 tasks
@blowsie
Copy link
Author

blowsie commented Nov 21, 2022

also fails on onRoutesGenerated

   onRoutesGenerated(routes) {
          return routes.map((route) => {
            return {
              ...route,
              props: (to) => ({
                test: 'it',
              }),
            }
          })
        },

@hannoeru
Copy link
Owner

hannoeru commented Nov 22, 2022

Because routes need to be serialize during build time then pass to frontend, so if you want to include some logic in props, try to extends routes in your entry point. ex. main.ts

@blowsie blowsie closed this as completed Nov 30, 2022
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