Vue Router is failing to match a URL that contains numerous dynamic parameters

I've been working on adding a nested url to my routes and have encountered an issue with the last route in my code. Every other route seems to be functioning properly.

I attempted to nest the urls using the children property, but it wasn't successful. However, I don't believe that's the approach I want to pursue anyway because I want to use a completely separate component instead of nesting <router-view>s.

Does anyone have any suggestions on how I can resolve this issue? I'm unsure about how to debug it. When I look at the Vue dev tools, all I see is a <RouterView> component with a prop: name: "default".

Below is a snippet from my routes.js file:

import VueRouter from 'vue-router';

import Search from './views/Search';
import FoodItem from './views/FoodItem';
import NutrientCategory from './views/NutrientCategory';
import NutrientDetail from './views/NutrientDetail';

let routes = [
  {
    path: '/',
    component: Search
  },
  {
    path: '/:id',
    component: FoodItem
  },
  {
    path: '/nutrients/:slug',
    component: NutrientCategory
  },
  {
    path: '/nutrients/:slug/:nutrient-slug',
    component: NutrientDetail
  }
]

export default new VueRouter({
  routes,
  linkActiveClass: 'active',
  scrollBehavior (to, from, savedPosition) {
    return { x: 0, y: 0 }
  }
});

Answer №1

The issue arises when attempting to utilize the minus symbol as the parameter name:

/nutrients/:slug/:nutrient-slug

However, the regular expression used by the path-to-regexp package for interpreting the path pattern utilizes the \w character class for the name pattern:

\w+ matches any word character (equal to [a-zA-Z0-9_])

Therefore, it is recommended to use an underscore instead of a minus symbol:

/nutrients/:slug/:nutrient_slug

[ https://jsfiddle.net/fhrekL25/ ]

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

Eliminating choices from a dropdown list using jQuery

I am currently working on a page that contains 5 dropdown menus, all of which have been assigned the class name 'ct'. During an onclick event, I want to remove the option with the value 'X' from each dropdown menu. My current code snipp ...

Occasional TypeError when receiving JSONP response using jQuery .ajax()

Occasionally, I encounter an error message stating Uncaught TypeError: undefined is not a function when processing the JSONP response from my jQuery .ajax() call. The JSON is returned successfully, but sometimes this error occurs during the reading process ...

Tips for testing parallel, mocked data requests in JEST by simulating cached responses with a 500ms limit

In order to simulate parallel requests fetching data from different sources, I have implemented tests that introduce artificial latency for each request. The goal is to return a simple string with an identifying digit to determine whether the data has been ...

Operating on Javascript Objects with Randomized Keys

Once I retrieve my data from firebase, the result is an object containing multiple child objects. myObj = { "J251525" : { "email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c3823212 ...

Using Angularjs: Trigger Directive Execution Post Completion of ng-init Function

I'm facing an issue with calling a function in ng-init within my HTML file. The function is responsible for making an API call and collecting data, which is then assigned to a scope variable and passed to a directive. Initially, the controller gets e ...

Having trouble rendering to the framebuffer due to issues with the texture

In the process of incorporating shadow maps for shadows, I am attempting to render a scene to a separate framebuffer (texture). Despite my efforts, I have not been able to achieve the desired outcome. After simplifying my codebase, I am left with a set of ...

Is it possible to select options in AngularJS based on certain criteria?

I created an AngularJS select menu that is currently functioning correctly: <select name="s1" id="s1" multiple="multiple" data-native-menu="false" data-role="none" ng-model="userlistSelect" ng-options="u.userId as u.fi ...

Console log messages not displaying in Express.js app method

const express = require("express"); const app = express(); app.listen(3000, function () { console.log("Server started at port 3000."); }); app.get("/", function (req, res) { console.log("Hello, world"); const truck = "drive"; res.send("Hello, ...

Tips for implementing focusout on multiple elements while avoiding it when switching focus between them

Looking to create a searchable input that displays a dropdown of possible values on focusin, populated by server-side language. Attempted using focusin on elements not involved with the following code: $("body").not($(".dropdownSearch") ...

"Exploring ways to implement validation for multiple email addresses in a textarea using JQuery or JavaScript, while allowing the addresses to be separated by semicol

NOTE: Each email ID must be unique. An empty string value is allowed to be added. Email IDs should be separated by semicolons and commas. Basic validation of email IDs is necessary for entry. [![ $("#d-notification").focusout(function () { var ...

What is the solution for resolving a 404 error when making a POST request using Axios in a

I am encountering a 404 error when trying to send a request to an API, and I can't find any leads in the network. Can anyone assist me with this issue? Here is my code: loginMethod() { const config = { userName: "<a href="/cdn-cgi/l/ ...

Steps for launching Angular 5 application using Node.js server

I have developed an Angular 5 application that retrieves data from a node.js server. I successfully deployed the application to my web server hosted by FastComet, which supports node.js, but unfortunately, the server does not seem to be functioning properl ...

Ways to establish a minimum height for material cards using Material UI

I am facing an issue with a card that contains a nested table. The card expands and shrinks based on the size of the table inside it. I want to prevent the card from shrinking when the table has no data or just one entry. Instead, I need the card to mainta ...

When using Mongoose and Socket.IO, an empty string will not be printed if the result is empty

I'm facing an issue with a filter I created using socket.io and mongoose. Specifically, I'm trying to display a message if there are no results returned when querying, but it seems to not be working as expected. Restaurant.find({ $text : { $sear ...

Using Vue components, a string can be interpolated to dynamically display content

Help me understand how to properly utilize the component for string interpolation. For instance, I have a component that functions as follows: Component-X <template> <div>{{someData}}</div> </template> When I integrate this co ...

Trouble with rendering the Vuetify v-sparkline component

I am seeking assistance with incorporating sparkline graphs into my component, as I am relatively new to this concept. Currently, I am trying to display a graph with default settings and an array of numbers passed in as a prop for the values. Although the ...

Differences between JavaScript array manipulation using the split(" ") method and the spread operator

I'm currently attempting to determine if a given sentence is a palindrome, disregarding word breaks and punctuation. The code snippet that utilizes cStr.split(" ") DOES NOT achieve the desired outcome. Although it splits on whitespaces (&qu ...

Utilizing JQuery to Extract Data from a Nested JSON Array

My API is returning a JSON string with various values that I need to extract using JQuery. "[ ["West Baton Rouge test hello world", "1"], ["LSU Parking \u0026 Transportation Services", "2"], ["demokljafsk", "3"], ["latest", "19"], ...

Having trouble getting my app.get calls to work in the new Node Express project

Recently, I kicked off a new project and encountered a perplexing issue - my app.get method simply refuses to be invoked. The site keeps loading indefinitely without any content being displayed. Initially, I copied and pasted the code from another project ...

My goal is to prevent users from using the Backspace key within the input field

Let's say we want to prevent users from using the backspace key on an input field in this scenario. In our template, we pass the $event like so: <input (input)="onInput($event)"> Meanwhile, in our app.component.ts file, the function ...