-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Share routes with front frameworks like Inertia/VueJS #68
Comments
Hi, This package overrides Laravel's I assume that the JS helper doesn't use the backend, thus the locale prefix isn't applied. |
Your problem is quite easy to fix. In your
Then in your Vue components, instead of using |
I am currently using React with Inertia. I use the ...
import { useTranslation } from "react-i18next";
export default () => {
const { i18n } = useTranslation();
const localizedRoute = route(i18n.language + ".index");
return (
<>
</>
);
} The React package knows exactly which translation is being used so it always shows the correct localized route. |
How I solved it with vuejs inertiajs + ssr following @cv-chameleon help //HandleInertiaRequests.php
//...
return [
...parent::share($request),
'locale' => App::currentLocale(),
'auth' => [
'user' => $request->user(),
],
'ziggy' => fn () => [
...(new Ziggy)->toArray(),
'location' => $request->url(),
],
]; //app.js
import { createInertiaApp, usePage } from "@inertiajs/vue3";
//...
.mixin({
methods: {
$route: (name, params, absolute, config) =>
route(
`${usePage().props.locale}.${name}`,
params,
absolute,
config
),
},
}) //ssr.js
import { route, ZiggyVue } from "../../vendor/tightenco/ziggy";
//...
setup({ App, props, plugin }) {
const Ziggy = {
...page.props.ziggy,
location: new URL(page.props.ziggy.location),
};
return createSSRApp({ render: () => h(App, props) })
.use(plugin)
.mixin({
methods: {
$route: (name, params, absolute, config = Ziggy) =>
route(
`${page.props.locale}.${name}`,
params,
absolute,
config
),
},
})
.use(ZiggyVue, Ziggy);
}, |
Hello !
Is it possible to generate routes correctly with Inertia using your package ?
With Inertia, the Ziggy library is used. After debugging, my route list contains for example:
And calling route('dashboard') function in inertia does not work.
The text was updated successfully, but these errors were encountered: