Jan 23, 2025
0
Level 1
Skip pages for Inertia SSR
Hey none of the existing solutions:
Can Inertia's SSR Feature Be Enabled Only for Some Pages?
helped me to fix the issue, that my ssr.js file is still beeing called on page refreshes and returns the following error:
TypeError: Cannot read properties of undefined (reading 'location')
at setup /bootstrap/ssr/ssr.js:32:44)
at /node_modules/@inertiajs/vue3/dist/index.esm.js:1:6122
at async L (/node_modules/@inertiajs/vue3/dist/index.esm.js:1:6040)
at async Server.<anonymous> (/node_modules/@inertiajs/vue3/node_modules/@inertiajs/core/dist/server.esm.js:1:527)
It's because I don't pass ziggy routes to some of my pages:
ssr.js
import {createInertiaApp, Head, Link} from '@inertiajs/vue3';
import createServer from '@inertiajs/vue3/server'
import { renderToString } from '@vue/server-renderer';
import { createSSRApp, h } from 'vue';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { createPinia } from 'pinia';
import { ZiggyVue } from 'ziggy-js';
const pinia = createPinia();
createServer((page) =>
createInertiaApp({
page,
render: renderToString,
// title: (title) => `SSRTest`,
resolve: (name) =>
resolvePageComponent(
`./Pages/${name}.vue`,
import.meta.glob('./Pages/**/*.vue'),
),
setup({ App, props, plugin }) {
return createSSRApp({
render: () => h(App, props),
})
.use(plugin)
.use(pinia)
.use(ZiggyVue, {
...page.props.ziggy,
location: new URL(page.props.ziggy.location),
})
.component("Link", Link)
.component("Head", Head);
},
}),
);
I also tried it via a Middleware:
use Closure;
use Illuminate\Http\Request;
class DisableSSRForCertainRoutes
{
public function handle(Request $request, Closure $next)
{
if ($request->routeIs('admin.*')) {
config(['inertia.ssr.enabled' => false]);
}
return $next($request);
}
}
is there any way to exclude some pages from inertia?
Please or to participate in this conversation.