-->

Can we combine the SPA concept with dynamic nested

2019-08-28 16: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'