How to use inertia SSR route() in setup #564
-
Ziggy version1.4.6 Laravel version8.83.14 DescriptionI follow jetstream document and try to start new project ssr with this command
in
in
Ziggy call and context<template>
<div>
<h1>test</h1>
<a :href="url">link</a>
<a :href="route('home')">link</a>
</div>
</template>
<script>
export default {
name: "Welcome",
components: {
},
data() {
return {
url: route('home')
}
},
}
</script> Ziggy configuration{
url: 'http://localhost:8000',
port: 8000,
routes: {
home: {
methods: {
0: 'GET',
1: 'HEAD'
},
uri: 'home'
}
}
} Route definitionRoute::get('/home', function () {
return Inertia::render('Welcome', [
'canLogin' => Route::has('login'),
'canRegister' => Route::has('register'),
'laravelVersion' => Application::VERSION,
'phpVersion' => PHP_VERSION,
]);
})->name('home'); |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Your setup looks correct to me, but in setup() {
const route = inject('route');
// etc.
} Let me know if that works! See also: |
Beta Was this translation helpful? Give feedback.
-
@bakerkretzmar working now. resolved inside component script tags with |
Beta Was this translation helpful? Give feedback.
-
I tried every solution I could find and always this same error ReferenceError: route is not defined when using ssr. Ziggy: v1.5.0 This is my ssr.js
PageLayout.vue where error is thrown:
Inertia middleware share method
|
Beta Was this translation helpful? Give feedback.
Your setup looks correct to me, but in
setup()
there's nothis
so you can't use the mixin. Since Ziggy 1.4.4 though the route function is also injected everywhere by the plugin, so you should be able to use it insetup()
like this:Let me know if that works! See also: