Comments (11)
One way would be to generate router.js with node : get datas from your CMS and write / update your file router.js on the server / filesystem. You will need to set a cron.
from router-module.
hum, smarter than the cron : when creating a new page on cms side, you could do an http POST request to your nuxtjs app with all paths datas. (your nuxtjs application could expose some /api/paths with express & node; and this api would write your router.js file )
from router-module.
Can this module be async? Something like:
export async function createRouter() {
let routes = await axios.get('/routes.json')
return new Router({
mode: 'history',
routes: routes.map(route => {
return {
path: route.path,
component: components[route.template]
}
})
})
}
I might be doing something wrong here, but if I do like above, I get this error message: "router.resolve is not a function"
from router-module.
@ksolberg nope it can't but it might be useful.
In my case i would like to let Drupal 8 handle aliases / url-rewriting, so this would be a good place to do it. (i can ask Drupal : "what is the Drupal context for '/my-clean-url', and it can answer me : " this is an alias for a page content type, user is connected and current language is english". )
The only route i would need in this case would be "/:alias" in my router, and a dynamic component for it.
from router-module.
Hi,
Actually createRouter cannot be asynchronous since it's nuxt.js which handle this, otherwise, I suggest that you have a /*
route and then you can call your API to check if the route exists or no.
PS: please mention me so I can keep track of this issue.
from router-module.
@Atinux could you be more precise on that point ?
I suggest that you have a /* route and then you can call your API to check if the route exists or no.
It tried something like this
{
path: '/:path*',
component: Index
}
and the Index component use dynamic components to load the right component given a webservice called in Index.
BUT i loose SSR since it is only available for component declared in the router.
In any case, this is not the way nuxt is supposed to work, so not sure i should go further in this direction
PS : Hum, seems to me that this way of doing things is wrong. I want to use nice url-rewriting capabilities from Drupal, the best way would be to create url-rewriting with express / node server; calling Drupal aliases as a webservice.
PS-2 : but that won't work for client side -_-
from router-module.
I see @nyl-auster
You should not loose SSR since you will have asyncData
available into your Index
component and you can give this data to your dynamic component directly into it.
from router-module.
@Atinux yep right, thx, Index will have a lot of logic but it could be split in different files... that could work.
from router-module.
@jamestowers maybe this quick POC might help you : https://gist.github.com/nyl-auster/ecf5e4ac22ac4fd886b490441e7febd0
Router catch all paths with an "index" component. This index component call a webservice giving me info about which component i need to use according to what is returned by Drupal. Than i inject this component dynamically, passing it datas as props to get SSR working.
from router-module.
@nyl-auster Nice!
I'm using Laravel Lumen to run the CMS's API so when I get a sec i'll see if I can tweak your gist to get it to work with that.
Thanks.
from router-module.
@jamestowers i think this definitely an anti-pattern : the only "real" nuxt page component is then the "Index" one : you loose a lot of benefits of Nuxt (all custom page components properties like transition, layout etc ...).
The best way is to manually replicate router with Nuxt (or maybe generate it automatically if this is hardly needed : #4 (comment) )
from router-module.
Related Issues (20)
- base route is appended to url on page referesh HOT 1
- next() function is not working well HOT 1
- children in route.js don't work HOT 2
- Custom router in .nuxt folder HOT 2
- does it support nuxt3 with vue3 HOT 3
- Vue router 4 support HOT 6
- Release HOT 1
- Cannot start nuxt: Cannot find module 'nuxt/lib/app/router' in nuxt3 HOT 5
- Readme "If you are using Nuxt < 2.16.0, the parameter store is not available" HOT 2
- the css load order changes after using @nuxtjs/router
- Cannot extend routes from a module
- Code splitting not working with router.js HOT 3
- `Cannot read properties of undefined (reading 'options')` on add @nuxtjs/router to Nuxt 3 project HOT 1
- Docs: Missing correct docs about the `store` parameter.
- Can I access to the routes within another module?
- Anchor link dont work on yarn generate
- Is this module compatible with SSG build?
- Nuxt 3 Support HOT 1
- Nuxt content not generate or parse to custom router
- Hydratation error with SSG 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 router-module.