Reputation: 2031
I have this url structure:
http://localhost:3000/apps/projects/update/5
How can I get the number 5 from the URL using Vue JS way?
I am trying with this code:
let urlParams = new URLSearchParams(window.location.search);
Thanks.
Upvotes: 0
Views: 72
Reputation: 2626
The best way to do that is to add vue-router to your project. Then you can define dynamic routes, like:
const routes = [
{ path: '/apps/project/:id', component: Project },
]
In this example, the :id
defines a dynamic parameter. Than, in the Project component you can use the id variable:
const route = useRoute()
const urlParams = route.params.id;
Hope this helps.
Upvotes: 1