[Vuejs]-How to remove %20 and other special characters from a URL in NUXTJS?

1👍

have you tried decodeURIComponent() ?

console.log(decodeURIComponent(country.name));
👤il4mb

0👍

I know it’s too late but,I suggest this method.In fact,%20 replaces the space in your link.I suggest that you should remove all the spaces in your link before routing to it:

As an example

<script>
   export default{
         methods:{

         VisitLink(name) {

              this.$router.push(name.trim().replace(/ /g, "- 
             ").toLowerCase());
},
         }
   }
</script>

I use the method trim() to make sure that there is not any space at the end of country name. Then,I remove the all the remaining space in NAME.
But,if you still want to use nuxtJs link you can create a method like

<script>
 export default{
   methods:{
    getLink(name){
       return  name.trim().replace(/ /g, "- 
             ").toLowerCase()
     }
    }
  }
</script>

and then

<nuxt-link :to="getLink(country.name)"><span>Learn more...</span></nuxt-link>

I hope,it could help someone

Leave a comment