0

我正在尝试在 laravel 中将SSR 惯性与反应一起使用。

版本详情:

PHP:8.1.2
Laravel:8.82.0
微风:1.7.1
惯性:0.11.0 Npm
:8.1.2

/resources/js/ssr.js

createServer((page) => createInertiaApp({
  page,
  render: ReactDOMServer.renderToString,
  resolve: name => require(`./Pages/${name}`),
  setup: ({ App, props }) => <App {...props} />,
}))

/webpack.ssr.mix.js

mix
  .options({ manifest: false })
  .js('resources/js/ssr.js', 'public/js')
  .react()
  .alias({ '@': path.resolve('resources/js') })
  .webpackConfig({
    target: 'node',
    externals: [nodeExternals()],
  })

/resources/views/app.blade.php

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        ...
        <link rel="stylesheet" href="{{ mix('css/app.css') }}">
        @routes
        <script src="{{ mix('js/app.js') }}" defer></script>
        @inertiaHead
    </head>
    <body class="font-sans antialiased">
        @inertia

        ...
    </body>
</html>

错误:

ReferenceError: route is not defined
at Welcome (/public/js/ssr.js:1413:19)
4

1 回答 1

0

你试过这个吗?它在路由 - 惯性中。

app.config.globalProperties.$route = route

于 2022-03-04T14:29:23.673 回答