Error with opening url in other tab in js code

Viewed 328

In my Laravel 5.8 / "vue": "^2.6.10"/ app I need to open url in other tab in js code. I found example

let routeData = this.$router.resolve({name: 'routeName', query: {data: "someData"}});
window.open(routeData.href, '_blank');

here Can vue-router open a link in a new tab?

but implementing it I did not find valid way :

let routeData = this.$router.resolve(  {name: 'editHostel', query: {params: { id : 48 } }  });


            OR

let routeData = this.$router.resolve(  {name: 'editHostel', query: {id: date.id}}  );


        window.open(routeData.href, '_blank');

in both case generated url was invalid.

In resources/js/routes.js I have :

{
    path: '/admin/hostels',
    component: hostelsContainer,
    meta: {
        requiresAuth: true,
        authGroupsAccess: ['Admin', 'Manager'],
    },
    children: [
        {
            path: '/admin/hostels/',
            component: hostelsList,
            name: 'listHostels'
        },
        {
            path: '/admin/hostels/new',
            component: editHostel,
            name: 'newHostel'
        },
        {
            path: ':id',
            component: editHostel,
            name: 'editHostel'
        },

Which way is valid ?

2 Answers

I found a decision based on link Can vue-router open a link in a new tab? as :

let routeData = this.$router.resolve(  { path: '/admin/hostels/' + date.originalEvent.hostel_id +"/open_hostel_inquery_feedback/"+date.id});
window.open(routeData.href, '_blank'); 

That works for me!

Don't make SPA(single page application) within laravel. If you really want to create SPA then use vue cli

Otherwise, use vue.js as a replacement for jQuery. That gives you more power of making an interactive website using laravel and vue.js in a single project.

You will be able to use blade views where you don't have to use vue and vice versa.

Related