This commit is contained in:
F4ilji
2026-04-07 22:30:06 +05:00
parent 438f7df855
commit 3798d01da1
2 changed files with 30 additions and 6 deletions
@@ -14,11 +14,11 @@ export default {
props: {
title: {
type: String,
required: true, // Сделаем title обязательным
required: true,
},
link: {
type: String,
required: true, // Сделаем link обязательным
required: true,
}
},
computed: {
@@ -28,10 +28,20 @@ export default {
new URL(this.link);
return this.link; // Если это валидный URL, возвращаем его
} catch (e) {
// Если это не валидный URL, предполагаем, что это название роута Inertia
// Убедитесь, что функция route() доступна глобально или импортирована
// (обычно она доступна в Laravel-приложениях через Inertia)
return route(this.link);
// Если это не валидный URL, предполагаем, что это название роута
// Используем this.route() который доступен через ZiggyVue mixin
if (typeof this.route === 'function') {
try {
return this.route(this.link);
} catch (err) {
console.error('Route function failed:', err);
return '#';
}
}
// Fallback: возвращаем ссылку как есть или хэш
console.warn('route() function is not available');
return '#';
}
}
}
+14
View File
@@ -4,6 +4,7 @@ import createServer from '@inertiajs/vue3/server'
import { renderToString } from '@vue/server-renderer'
import { createSSRApp, h } from 'vue'
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';
import { default as Router } from '../../vendor/tightenco/ziggy/dist/index.m.js';
createServer(page =>
createInertiaApp({
@@ -32,6 +33,19 @@ createServer(page =>
ziggyConfig.location = new URL(process.env.APP_URL || 'http://localhost');
}
// Создаем функцию route с правильной конфигурацией
const route = (name, params, absolute, config) => {
const ziggyConfigForRoute = {
...page.props.ziggy,
location: ziggyConfig.location,
};
const router = new Router(name, params, absolute, ziggyConfigForRoute);
return router.toString();
};
// Делаем route доступным глобально
ssrApp.config.globalProperties.route = route;
return ssrApp
.use(plugin)
.use(ZiggyVue, ziggyConfig);