Comments (9)
Fixed in 0.9.6
from vite-plugin-pages.
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.
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.
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.
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.
Thanks. Good to know that two options are available.
from vite-plugin-pages.
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.
Thank you
from vite-plugin-pages.
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)
- [Question] - How to define title, meta, middlewares for React? HOT 1
- Route with params/props (Not in URL) HOT 1
- Routes with extensions are not supported. HOT 1
- [Question] Is it possible to differentiate links to prevent all getting router-link-active by expanded parameter's?
- Only index file under pages folder accessible in deployed app
- exclude not work when file change HOT 2
- TSX/JSX consider support to define meta by jsdoc with import types
- How to add meta in route HOT 11
- catch all route not catch index route HOT 1
- Vulnerability : Update yaml to 2.2.2
- Add dynamic meta to dynamic routes HOT 1
- The field name "filePattern" in the config contains a spelling error. HOT 1
- Dynamic routing + dynamic tab + sub route
- [Feature] Typescript support for route path and route path params(Auto complete) HOT 1
- doesn't React support the feature [SFC custom block for Route Data ]?
- Vite5.0 support HOT 3
- Support for v0.10 @solidjs/router ?
- path: '*'
- keepAlive cache invalidation
- Reduce the large bundle size HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vite-plugin-pages.