Tips for successfully using a string with a slash ("/") as a parameter in a route within vue.js

Currently, I am utilizing Vue Router with a specific route setup

{ path: '/my-route/:param?', component: MyComponent }

To link to this route, I have created the following link

<router-link :to="'/my-route/'+myParam">Link text</router-link>

The issue arises when myParam contains a string with '/' such as 'abc/def'. This results in navigation to a link /my-route/abc/def that does not exist. What is the best approach to resolve this problem?

Answer №1

To ensure proper encoding, utilize the JavaScript function encodeURIComponent(uri)

Make sure to modify your router-link

<router-link :to="'/chosen-path/'+encodeURIComponent(myParameter)">Text on Link</router-link>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Whenever I refresh my website after deployment, I encounter an empty error using the MERN stack

Here is a question I previously posted: How can I properly use the res.sendFile for my MERN APP, as I encounter an error every time I refresh, and it was resolved there. I encountered a similar issue here, even after following the same steps that worked b ...

The useNavigate function in React is causing an error due to its absence

In the past React version, Redirect could be used to switch from one page to another based on a certain condition. However, with v6, Redirect is no longer functional. import React, {useState, Redirect, useNavigate} from 'react'; import './Ap ...

Customize the position of nodes and their descendants in a d3 tree chart by setting specific x and y coordinates

I am in need of a d3 tree structure that looks like this. https://i.sstatic.net/X6U3u.png There are two key points to understand from the image above: Headers will have multiple parents(wells). I need to be able to drag and drop links connecting w ...

Converting objects into an array of arrays: A Step-by-Step Guide

My attempts have not yielded the desired outcome Object.keys(data).forEach(function (key) { console.log(data[key]); array = $.map(data[key], function(value, index) { return [value]; }); }); The output I encountered is - 0:{1: 2, 2: ...

Utilizing AWS Amplify to automatically synchronize changes in my Vuex state with updates in a DynamoDB table

Currently, I am integrating AWS amplify into my Vue.js application. The application involves a player state that retrieves data from the player table through the GraphQL API. I am looking for a way to automatically update the player state whenever there ...

How to make an angular Factory access its own data

I've been working on a project involving angular factories, and I'm encountering an issue where the factory is not able to reference some of its own data. Specifically, in the code snippet below, data2 should be reading the value from testVariabl ...

Unexpected 404 Error in Node.JS Express following a POST submission

I've recently built my first application using Express and MySQL. I'm encountering an issue with saving data in my database - every time I make POST requests, I receive a status 404 error and nothing beyond that. This roadblock is preventing me f ...

Steps to activate ng-pattern exclusively when the field has been interacted with:

I've encountered a challenge with an input box that has an ng-pattern for link validation. Our project manager has requested that the text 'http://' be pre-filled in the input field, but doing so breaks the ng-pattern validation and prevents ...

What is preventing this JSON object from being parsed correctly?

Within my JavaScript file, The process of declaring and parsing the ajax response text is as follows: var subcats = JSON.parse(this.responseText); The actual responseText that needs to be parsed looks like this: {"presubcatId":"1","precatId":"1","presu ...

Fetch data dynamically upon scrolling using an AJAX request

Instead of making an ajax call to load data, I want to do it on scroll. Here is the code I have: $.ajax({ type: 'GET', url: url, data: { get_param: 'value' }, dataType: ' ...

Unavailable dates on Datepicker (information fetched from the database)

I am currently working on extracting dates from my database and storing them in an array as json data. In my MAIN.PHP file: $('#datepicker').focus(function(){ $.ajax({ url: 'getDates.p ...

What is the best way to compare two arrays of data and make changes?

I am working with two arrays, array A and array B Here is how they look: A: [11, 14] B: [ { title: 'title 1', data: [ { node_id: 11, selected: false }, { node_id: 14, selected: false } ]}, { title: 'title 2', data: [ { node_id: 7 ...

Resolving ExpressJS routing issues while utilizing AngularJS html5Mode in the context of back4app/Parse-Server

I am currently utilizing the back4app BaaS service which operates on Parse-Server. On the ClientSide, I have integrated AngularJS with html5Mode set to true; The issue I am facing is that this link is not functioning as expected: However, this link works ...

Promise.each encountered an unhandled rejection

I'm currently facing a challenge in making multiple database queries using bluebird's Promise.each(). So far, I haven't been able to effectively handle rejections, especially when multiple promises fail. Interestingly, when attempting the sa ...

Steps for retrieving data from mySQL and displaying it in a Modal:1. Connect to

I have encountered an issue with displaying records from my table columns named tid and ketprob. When clicking on a link, I am trying to show a modal that contains the data. The modal appears correctly but is showing no data. Can someone please assist me w ...

Utilizing Vue's looping functionality to dynamically insert CSS class names

As a newcomer to Vue, I am facing an issue with handling an array of objects. My goal is to dynamically assign a className to the wrapper of a loop based on a condition. For instance: <div v-for="({time, date, name}, i) in myObject" :key=" ...

AngularJS modal directives trigger a reset of $scope variables

I am developing a custom AngularJS application that needs to handle and store all the checkbox selections made by the user in a simple array of IDs. The functionality includes displaying a modal when the open button is clicked, allowing the user to perform ...

Updating Mongoose References

When updating the Kwizz model with the password from req.body and team ID from req.session, it currently replaces the existing teams array. However, I am looking to simply add 1 to the array instead. I have searched for a solution but couldn't find a ...

Is there a way to link to a specific section within a webpage using its ID, landing halfway down the page instead of at the top?

Can someone help me out with this issue? The header on my page is fixed at the top and has a height of 75px. When I click on a link (<a href="/company/#contact/">contact</a>), it takes me to the right section but the top part is hidden behind t ...

display alternative text before an image is loaded on the screen

Is there a way to display text instead of an image before the image loads? I have a website with an image as the title, causing the page to load fully before the title image is loaded later. Is there a solution for this issue? ...