0

I am trying to configure a prerender-spa-plugin for my application.
Need to configure for multiple pages.

I do, as in documentation (Vue.js 2 Router)

I added the necessary parameters to file webpack.prod.config.js

const PrerenderSPAPlugin = require('prerender-spa-plugin')
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer

const webpackConfig = merge(baseWebpackConfig, {

...

  plugins: [

        // == PRERENDER SPA PLUGIN == //
        new PrerenderSPAPlugin({
            staticDir: path.join(__dirname, '../dist'),
            routes: ['/', '/test'],

            renderer: new Renderer({
                inject: {
                    foo: 'bar'
                },
                headless: false,
                renderAfterDocumentEvent: 'render-event'
            })
        }),
...

Also in the file main.js

new Vue({
  el: '#app',
  router,
    render: h => h(App),
    mounted () {
        // You'll need this for renderAfterDocumentEvent.
        document.dispatchEvent(new Event('render-event'))
    }
})

Now about the main problem. At the root(/) of the project, pre-rendering is working. If you go to the page /test, then in the source code (ctrl + u) will show the code from the site root(/).

I can't find content from /test in any way.

Tell me what I'm doing wrong, and how to fix the problem.

Thank!

UPD:routes.js

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import test from '@/components/test'

Vue.use(Router)

export default new Router({
    mode: 'history',
    routes: [
        {
            path: '/',
            name: 'HelloWorld',
            component: HelloWorld
        },
        {
            path: '/test',
            name: 'test',
            component: test
        }
    ]
})
4
  • In order to verify that prerender does not work as expected, please, check html output inside dist folder. There should be test folder with index.html. If it has valid content for that page, then it is possible that production server is not configured correctly. Commented Nov 14, 2018 at 13:15
  • @aBiscuit Inside this file is the code from the main page. Commented Nov 14, 2018 at 13:35
  • prerender-spa-plugin is pretty straightforward. Please, try removing additional configuration from new Renderer options and check if you have same results in generated files. Also, please, add router configuration to the question. Commented Nov 14, 2018 at 13:45
  • @aBiscuit I removed the parameter, nothing has changed. Added route Commented Nov 14, 2018 at 14:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.