Search code examples
vuejs3inertiajslaravel-9

How to pass route param while using Inertia manual visit


How can I pass the route param while using Inertia manual visit, for example:

Route:

Route::post('/explore/gallery/like/{$post}', [ExploreController::class, 'likeToggle'])
    ->name('explore.post.like');

Component:

Inertia.visit(route('explore.post.like'),
                {
                    method: 'post',
                    preserveScroll: true,
                    data: {
                        $post: this.id
                    },
                },
            );

but is shows the error tho,

enter image description here


Solution

  • A simple solution would be:

    Inertia.post(route('explore.post.like', [this.id, 'if you have other params']), {}, {
                    preserveScroll: true,
                });
    

    Pls make sure the order is correct, follow the order of your route's param