P粉9044059412023-08-26 12:02:31
First of all, you don't need to add mode: 'universal'
to the configuration, just add target: 'static'
to simplify the configuration. Learn more - https://nuxtjs.org/docs/2.x/features/deployment-targets/. With ssr: true
you will get a fully static mode website with relevant hooks as described in https://stackoverflow.com/a/65208463/8153537.
Next, you can remove the @nuxt/router module. Check out my gist - https://gist.github.com/MexsonFernandes/d04495c86b115bbe29f26b36b0b35d2d. Nuxt generates all required routes based on the folder structure, so no additional configuration is required.
Check out this gist for project page routing - https://gist.github.com/MexsonFernandes/d04495c86b115bbe29f26b36b0b35d2d#gistcomment-3555332.
P粉7528260082023-08-26 00:46:34
router.mode='hash'
appears to be incompatible with the generate.routes
configuration. When router.mode
is set to hash
, the Nuxt generator ignores generate.routes and only creates a route for /
, this is probably because the homepage is only expected to exist in hash
mode (i.e. index.html
has a route set up that handles all routes for the application).
This hash mode also conflicts with the mode set in router.js, but if you really need hash routing, you should choose only in router.js
Set this in # to allow processing of generate.routes
.
Also note that mode='universal'
is equivalent to ssr=true
, so the configuration ssr=false is not available in this mode significance. If generating a static site, you need ssr=true
so that any asyncData()
and fetch()
hooks can be called to populate the static page data. This setup also eliminates the need to add /about,
/contact and
/portfolio in
dynamicRoutes()
# because they are already included in the generated route.