score:0

Accepted answer

Apparently there is no alternative to nodejs server, which is not an option for me currently, so I unfortunately had to abandon next.js and create a CRA app and used as much from the next.js as I could.

score:2

Actually the acepted answer is completly wrong, when you do yarn build and in your package.json is set like "build": "next build && next export", you will get an out folder which all the items in there are used to build without node.js server

Now since you are using laravel, and you use the out folder you will only load half of the page because the routes are not set properly. for that to work you need to edit your next.config.js edit it to

module.exports = {
 distDir: '/resources/views',
 assetPrefix: '/resources/views',
}

These will set the root directory to the root one in Laravel. now this will work for SPA (single page application) only for the dynamic routes you need to match with a view file for each one that you have in your out folder

For each route that you have you need to create a new "get" route in laravel

Route::get('/', function () {
  return require resource_path('views/index.html');
});

Route::get('/contacts', function () {
  return require resource_path('views/contacts.html');
});

Route::get('/post/{slug}', function () {
  return require resource_path('views/post/[slug].html');
});

Notice that you can pass a wildcard for dynamic routes and they are all gonna work. once you do that and you deploy route out folder inside /resources/views in Laravel it's going to work


Related Query

More Query from same tag