hannoeru / vite-plugin-pages

File system based route generator for ⚡️Vite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

extendRoute does not support JS

blowsie opened this issue · comments

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.

also fails on onRoutesGenerated

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

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