GithubHelp home page GithubHelp logo

Comments (9)

hannoeru avatar hannoeru commented on May 28, 2024 2

Fixed in 0.9.6

from vite-plugin-pages.

bfourgeaud avatar bfourgeaud commented on May 28, 2024 1

Hello,

I am facing the same problem. Would someone have any example how to use that includedRoutes option to build pages from an api call ?
I would have to retrieve all the dynamic pages before building in order to have ServerSideGenreration on these dynamic pages and make these pages SEO friendly ...

Thank you very much !

from vite-plugin-pages.

hannoeru avatar hannoeru commented on May 28, 2024

vite-ssg will take routes array from vite-plugin-pages, so if you use vite-plugin-pages's onRoutesGenerated hook you can replace /[id].vue dynamic route to static route from 1-10 then vite-ssg will rander it.

from vite-plugin-pages.

husayt avatar husayt commented on May 28, 2024

Thanks, that has worked, but there is one issue.
Before for a page [id].vue I could access id through props, but not anymore. So the following stopped working

const props = defineProps({
 id: {
    type: String,
    default: "1",
  },
})

from vite-plugin-pages.

hannoeru avatar hannoeru commented on May 28, 2024

Umm, if you need props from dynamic route, the original way is better.
keep dynamic route & use vite-ssg's includedRoutes option to generate it.
Nuxt.js is also doing that way.

from vite-plugin-pages.

husayt avatar husayt commented on May 28, 2024

Thanks. Good to know that two options are available.

from vite-plugin-pages.

husayt avatar husayt commented on May 28, 2024

Hi @hannoeru there is a bug with onRoutesGenerated. Each time it;s being called in dev it passes routes from previous call.
So if there were 5 routes initially and I added 10 inside onRoutesGenerated. On second call routes have 15 items, on third call 25 and so on.

from vite-plugin-pages.

husayt avatar husayt commented on May 28, 2024

Thank you

from vite-plugin-pages.

joshbmarshall avatar joshbmarshall commented on May 28, 2024

I use something like this:

export async function includedRoutes(paths, routes) {
  const newroutes = []
  for (let i = 0; i < routes.length; i++) {
    const route = routes[i]
    if (route.path.includes(':')) {
      // I don't want any pages with variables rendered, will add them manually below
      continue
    }
    if (route.path == '/gallery') {
      // I don't want the gallery page rendered
      continue
    }
    newroutes.push(route.path)
  }

  const products = (await axios.get('/api/call/list/of/products')).data.map(item => `/product/${item.slug}`)
  for (let a = 0; a < products.length; a++) {
    newroutes.push(products[a])
  }

  return newroutes
}

from vite-plugin-pages.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.