Home > Mobile >  Get parameter from URL in Vue JS
Get parameter from URL in Vue JS

Time:10-20

I am working on SPA (Vue JS) and Laravel as API. I want when users will receive email to click on button that will sent them to specific route (already implemented).

So now i am struggling how to get the user id from the Vue JS part.

https://domain.test/admin/users/dashboard/user/65/show

65 from the URL is the user ID, so any idea how to extract that ID with java script from Vue JS?

I am not using vue router, this is Laravel route and Vue JS component is rendered from blade file.

I have implemented something like this bellow, but client refused...

https://domain.test/admin/users/dashboard/user/show?userId=65

CodePudding user response:

let id = window.location.href.split('/').slice(-2)[0]

CodePudding user response:

Since you're already rendering the page in a Blade file, you should already have access to the user ID server side.

In that case, simply add the variable server side. For example:

<a :href="'https://domain.test/admin/users/dashboard/user/'   {{ 
$user->id }}   '/show'">Go to Dashboard</a>
  • Related