Can we combine the SPA concept with dynamic nested routes in Nuxt.js?

北战南征 提交于 2019-12-11 15:58:29

问题


In my Nuxt.js application, I have to use dynamic nested routes. This means I will end up by having various HTML files generated. The problem is that I must embed my whole application within an existing website, on a specific page, to be precise. In the beginning I thought only one page will be needed, but finally I ended up by having multiple pages.

  1. How can I embed my files given these constraints? Any approach?
  2. Is it possible to combine the SPA concept with dynamic nested routes?

回答1:


These concepts are not mutually exclusive, you only need to set the nuxt.conf.js mode into 'spa' and you can leave everything else in place.

As per the official documentation:

So, for an SPA deployment, you must do the following:

  • Change mode in nuxt.config.js to spa.
  • Run npm run build.
  • Deploy the created dist/ folder to your static hosting like Surge, GitHub Pages or nginx.

without any further configuration you should be set to deploy your app.

Also note this:

nuxt generate still needs SSR engine during build/generate time while having the advantage of having all our pages pre rendered, and have a high SEO and page load score. The content is generated at build time. For example, we can't use it for applications where content depends on user authentication or a real time API (at least for the first load).

This means that you need to generate your page in an environment where the ssr tools are installed.

Also the next parragraph




回答2:


I confirm that we combine SPA and dynamic nested routes.
All what to do is to declare the dynamic routes within nuxt.config.js file and set: mode: 'spa'



来源:https://stackoverflow.com/questions/52820584/can-we-combine-the-spa-concept-with-dynamic-nested-routes-in-nuxt-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!