У вас есть два подхода, первый - запросить страницу и создать поведение на основе json
или api
.
Попробуйте использовать:
const Nuxt = require('nuxt')
const nuxt = new Nuxt()
nuxt.build()
.then(() => {
// here you can use nuxt.renderRoute() or nuxt.render(req, res)
});
Например:
nuxt.build()
.then(() => nuxt.renderRoute('/'))
.then(({ html, error, redirected }) => {
// Use Html as string
// `error` not null when the error layout is displayed, the error format is:
// { statusCode: 500, message: 'My error message' }
// `redirected` is not `false` when `redirect()` has been used in `data()` or `fetch()`
// { path: '/other-path', query: {}, status: 302 }
})
Второй подход заключается в создании маршрута:
app.get( '/', ( req, res, next ) => {
doThePromise( req.query )
.then( data => {
console.log( "rendering", res.renderRoute );
res.renderRoute( 'pages/foo', { data: data } );
} );
} );
Или так просто, как:
app.get('/route', (req, res) => {
res.render('foo')
})