-1

this is my json object ,i'm trying to access jackets in my url

{
  "_id": "6316f215fd9c107baa1bc160" 
  "type": "Jackets",
}

this is my router component to get product by id

 {
    path: "/product/:id",
  },

if i want to get my product information by id

 <router-link :to="`/product/${product._id}`">
                  <div
                    class="bg-image hover-zoom ripple"
                    data-mdb-ripple-color="light"
                  >
                    <img
                      src="../../assets/pexels-baskin-creative-studios-1766838.jpg"
                      class="card-img-top"
                    />

                  </div>
                </router-link>

this is my url

http://localhost:8082/product/6316f215fd9c107baa1bc160

i get jackets in my template after clicking the router-link

{{product.type}}

how can i get add jackets in my url to something like this


http://localhost:8082/product/jackets

and still display the json details in my template component

1 Answer 1

1

As per my understanding, You want to slightly change the current route path without refreshing/reloading the page. If Yes, You can achieve that by using history.replaceState() API.

history.replaceState({}, '', this.$route.path + '/' + <your product name>)
7
  • I'm trying to bind the title property to my url and display the product details under the url....just like get an element by id
    – jibzy
    Commented Sep 18, 2022 at 16:28
  • @jibzy Yes I understood that. Did you tried the solution I provided ? Commented Sep 18, 2022 at 17:06
  • If I may ask where do I place this
    – jibzy
    Commented Sep 19, 2022 at 7:24
  • In your component method, before or after making an API call. Commented Sep 19, 2022 at 7:31
  • this what i get in my url....localhost:8082/blog/63246b5147953ee6907f7337/title , this how i placed it in my mounted hook history.replaceState({}, '', this.$route.path + '/' + "title" ) .....how can i make it dynamic to get jackets thank you
    – jibzy
    Commented Sep 19, 2022 at 7:50

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.