I made a Laravel Nova tool, because I have needed some custom functionalities which Laravel nova can’t handle. Now my tool is finished and I want to go to another page from that tool.
I tried almost everything to fix this issue, but I could not find any solution. The nova documentation is lack of this information, and the steps in the Vue docs are not working.
I’ll provide some snippets what I tried so far:
// Tool.vue
<template> ... </template>
<script>
import Vue from 'vue';
import { useRouter } from 'vue-router'; // the package is installed
const router = useRouter();
export default {
// ...
method: {
someMethod() {
router.push('/someUrl');
this.router.push('/someUrl');
this.$router.push('/someUrl');
}
}
}
</script>
...
Out of these three none of them is working.
I get this error message in console:
Cannot read properties of undefined (reading 'push')
So the router object can’t be reached anyhow.
I also tried tweaking something in the tool.js:
// tool.js
import Tool from './pages/Tool'
import VueRouter from 'vue-router'
Nova.booting((app, store) => {
Nova.inertia('CustomTool', Tool)
app.use(VueRouter)
})
Or
// tool.js
import Tool from './pages/Tool'
import MyComponent from '../MyCompnent'
Nova.booting((app, store) => {
Nova.inertia('CustomTool', Tool)
app.component('MyComponent', MyComponent)
})
// Tool.vue
<template> ... </template>
<script>
import VueRouter from 'vue-router';
const router = new VueRouter({
routes: [
{
path: '/app/my-component',
component: MyComponent,
},
],
});
</script>
This way the error says that MyComponent is not defined. If I import it then it says that the VueRouter is not a constructor. If I change it like
const router = VueRouter.createRouter({
history: VueRouter.createWebHistory(),
routes: [
{
path: '/app/my-component',
component: MyComponent,
},
],
});
then simply says Cannot read properties of undefined (reading 'createRouter')
So my question is anyone tried to work with Laravel Nova tools like this before? If so, then how can I solve this issue. Note that, I want to pass some information from one page to another so the window.location.href = '/someUrl' isn’t an option.