antfu-collective / vite-ssg

Static site generation for Vue 3 on Vite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SSG for just home page?

atif0075 opened this issue · comments

How can I add SSG to my home "/" route while other routes remain the same?

main.js

import { createApp } from "vue";
import "./styles.css";
import App from "./App.vue";
const app = createApp(App);
import { ViteSSG } from 'vite-ssg';

// Install all modules under `modules/`
const moduleFiles = import.meta.globEager("./modules/*.js");
Object.values(moduleFiles).forEach((module) => {
  if (module && module.install) {
    app.use(module);
  } else if (module.default && module.default.install) {
    app.use(module.default);
  }
});

app.mount("#app");

./modules/router.js

import router from "../router/routes";
export default {
  install: (app) => {
    app.use(router);
  },
};

Router Config with unplugin-vue-router and vite-plugin-vue-layouts
routes.js

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

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  extendRoutes: (routes) => setupLayouts(routes),
});
export default router;

How can I implement the SSG to "/" without disturbing the other, is it possible or not?

Hi @atif0075,

What are you trying to achieve here? A default vite installation seem to achieve exactly what you describe.
https://github.com/antfu/vite-ssg?tab=readme-ov-file#custom-routes-to-render