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

unable to work with unplugin-vue-router/vite #129

Closed
mathieu-gilloots opened this issue Dec 12, 2023 · 6 comments
Closed

unable to work with unplugin-vue-router/vite #129

mathieu-gilloots opened this issue Dec 12, 2023 · 6 comments

Comments

@mathieu-gilloots
Copy link

mathieu-gilloots commented Dec 12, 2023

Hello,
I think I'm missing something.
When I create a router, I use the setupLayouts() method.
In the output of the method, I get the right layout with the page as a children.
When I output the router.getRoutes(), I didn't get the layout and children only the page.

My code :

import { createRouter, createWebHistory } from 'vue-router/auto'
import { routes } from 'vue-router/auto/routes'
import { setupLayouts } from 'virtual:generated-layouts'
import type { RouterOptions } from 'vue-router'
import type { UserModule } from '~/types'

const importedRoutesWithLayout = setupLayouts(routes);
export const install: UserModule = (app) => {
  const router = createRouter(<RouterOptions>{
    history: createWebHistory(),
    routes: importedRoutesWithLayout,
  })
  console.log(importedRoutesWithLayout);
  console.log(router.getRoutes());

Output :
image

Versions used :
image

Any ideas ?
Thanks

@mathieu-gilloots mathieu-gilloots changed the title unable to work with unplugin-vue-router/vite unable to work with unplugin-vue-router/vite Dec 12, 2023
@JohnCampionJr
Copy link
Owner

Nothings jumping out at me. Can you provide a repro or compare to Vitesse? https://github.com/antfu/vitesse/blob/main/src/main.ts

@mathieu-gilloots
Copy link
Author

Hello,
Thanks for your answer.
I will try to create a repro.
The difference with vitesse : I'm not using VueSSG.
I create a router.

const router = createRouter(<RouterOptions>{
    history: createWebHistory(),
    routes: importedRoutesWithLayout,
  })

And I'm passing this router to Vue with use method :
Vue.use(router), before mounting the app.

@hihanley
Copy link

@mathieu-gilloots
Look at this: https://github.com/posva/unplugin-vue-router#extendroutes

You need to create router in this way:

import { createRouter } from 'vue-router/auto'
import { setupLayouts } from 'virtual:generated-layouts'

const router = createRouter({
  // ...
  extendRoutes: (routes) => setupLayouts(routes),
})

@JohnCampionJr
Copy link
Owner

Added this to README

@mathieu-gilloots
Copy link
Author

Hello @JohnCampionJr & @hihanley
Just tried, it's written in the doc of unplugin-vue-router.
Need to use the extendRoutes and it's works !

Thanks

@kissu
Copy link

kissu commented Sep 29, 2024

Not sure if anything changed but this is my working config with unplugin-vue-router

import { setupLayouts } from 'virtual:generated-layouts';
import { createRouter, createWebHistory } from 'vue-router';
import { routes } from 'vue-router/auto-routes';

const router = createRouter({
  history: createWebHistory(),
  routes: setupLayouts(routes),
});

extendRoutes was undefined for me.

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

4 participants