I am looking to incorporate a password recovery page into my login process, but I am facing difficulty navigating to it once the code has been modified

I'm looking to include a forgotten password option on my login page,

but I'm facing an issue when trying to navigate to it after updating the code.

The website is throwing the following error message:

  • [vue-router] uncaught error during route navigation
  • Uncaught (in promise) undefined
  • Maximum call stack size exceeded

Here's my old code snippet:

router.beforeEach((to, from, next) => {
  const isLogin = localStorage.getItem("token") == "ImLogin";
  var role = localStorage.getItem('roles');
  if (isLogin) {
    if (to.matched.every(item => item.meta.indexOf(role) > -1)) {
      next();
    } else {
      next('/tips');
    }
  } else {
    if (to.path !== "/login") next("/login");
    else next();
  }
});

And here's the new code snippet I've added for the forgotten password feature:

<v-btn
  class="font-weight-bold"
  style="color:#FF7D52"
  href
  @click.prevent="forgetPassword"
  text
  >forgetPassword
</v-btn>

forgetPassword() {
      this.$router.push("/forgetPassword");
    },
Updated router.beforeEach method:
router.beforeEach((to, from, next) => {
  const isLogin = localStorage.getItem("token") == "ImLogin";
  var role = localStorage.getItem('roles');
  if (isLogin) {
    if (to.matched.every(item => item.meta.indexOf(role) > -1)) {
      next();
    } else {
      next('/tips');
    }
  } else {
    if (to.path === "/forgetPassword") {
      next("/forgetPassword");
    } else {
      if (to.path !== "/login") next("/login");
      else next();
    }
  }
});

Answer №1

if (to.path === "/forgetPassword") {
      next("/forgetPassword");
}

As recommended by a user named Matt Ellen, the current code will cause an infinite loop as navigating to "/forgetpassword" triggers the router beforeEach hook repeatedly.

To fix this issue, simply use next(); instead.

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

Exploring the elements within array structures

I'm facing an issue with my API response. I'm trying to filter the links and check if the source and target name properties in each object match a specific string. However, I am having trouble accessing the name property. Any suggestions on how I ...

What is the best way to set parameters for a dynamic route?

I would like to navigate to the next page with a click event using a dynamic route. The route ID is retrieved from a Vuex store. When I click, the following URL is generated: http://localhost:8080/worklist/%7Bname:'worklistDynamic',%20params:%7B ...

Console log is not displaying the JSON output

I am currently working on implementing a notification button feature for inactive articles on my blog. I want to ensure that the admin does not have to reload the page to see any new submitted inactive articles. To achieve this, I am looking to use Ajax, a ...

I encountered an error in the console stating, "Uncaught ReferenceError: req is not defined," while trying to access req.query.id

Encountering the error 'Uncaught ReferenceError: req is not defined' when attempting to use req.query.id. Below is the content of my index.js file: const express = require("express"); const path = require("path"); const port = 8000; ...

Can webpack effectively operate in both the frontend and backend environments?

According to the information provided on their website, packaging is defined as: webpack serves as a module bundler with its main purpose being to bundle JavaScript files for usage in a browser. Additionally, it has the ability to transform, bundle, or ...

unable to render axios retrieved data in vuejs v-for loop

After checking VueDev tools, it appears that the axios get request is returning a data array. However, despite my efforts, I am unable to display this data. (I'm clearly new at this!) Any ideas on what step I may be missing? <template> < ...

Change all instances of the subtraction symbol to parentheses using jQuery

--html-- <table> <tr> <th>a</th> <th>b<th> </tr> <tbody class = "tabledata"> <tr>a</tr> <tr>b</tr> </tbody> </table> --jquery-- $('.tabledata').empty(); for ( ...

React App PWA ERROR: Service worker not registered to control the page and start_url

I am encountering an issue while building a progressive web app using Create React App. Lighthouse benchmarking results in an error, indicating that my PWA is not installable. Surprisingly, I face the same problem even when utilizing the official PWA templ ...

Is it possible that using npm link could be the root cause of the "module not

As I delve into understanding how to utilize TypeScript modules in plain JavaScript projects, it appears that I am facing a limitation when it comes to using npm linked modules. Specifically, I can successfully use a module that is npm-linked, such as &apo ...

Issues arise when attempting to smoothly scroll to an anchor point in a webpage

While working on my website, I have encountered a challenge. The issue arises when dealing with multiple div items. Upon scrolling slightly, the entire page focuses on the div with a height of 100vh, which works perfectly fine. However, my attempts to ...

Exploring the world of handling GET and POST parameters in Node.js with

As someone who is new to Node/Express, I've noticed that GET parameters can be captured using the following syntax: app.get('/log/:name', api.logfunc); For POST requests, it can be done like this: app.post('/log', ... (with for ...

When an input in Vue.js registers a @keyup event, it will return to the parent

I am encountering an issue with my input component where pressing enter redirects me to the parent component. Even adding a @keyup event does not solve the problem. Could this be happening because I am in a child component? How can I prevent the enter key ...

Issue with Laravel Nova's Tool.vue: Arrow functions are not functioning properly in computed properties

I am facing an issue with a computed property that is not functioning correctly. After referring to the Vue 2.x documentation, here is the code I have: <template> <div> <button :disabled="isDisabled">Import configurator data ...

Module or its corresponding type declarations not found in the specified location.ts(2307)

After creating my own npm package at https://www.npmjs.com/package/leon-theme?activeTab=code, I proceeded to set up a basic create-react-app project at https://github.com/leongaban/test-project. In the src/index.tsx file of my react app, I attempted to im ...

Getting an image from a NodeJS backend to a React frontend

I successfully uploaded an image using the multer library in Express, storing it in the path Backend->Uploads/ and saving the image path in MongoDB. My project is structured as DirectoryName Backend Uploads Frontend While I can access the ima ...

HTML structure consisting of a 3 by 3 grid

Creating a 3x3 grid with cells that have varying heights depending on content is proving to be challenging. Except for the cells marked with red arrows, the rest of the grid has fixed height in pixels. I attempted to build a 3x3 grid using divs to experi ...

Identify data points on the line chart that fall outside the specified range with ng2-charts

I'm struggling to figure out how to highlight specific points on a line chart that fall outside a certain range. For instance, if the blood sugar level is below 120, I want to display that point as an orange dot. If it's above 180, I want to show ...

Using an npm package: A step-by-step guide

Recently, I added the following package to my project: https://www.npmjs.com/package/selection-popup I'm curious about how to utilize its features. Can you provide some guidance on using it? ...

Generate a random number in PHP with the click of a button

Hello, I have a scenario where I am working with two PHP pages. One page generates random numbers and the other displays them on a page refresh. I would like to find a way to retrieve the current random value by clicking a button instead of refreshing t ...

Configuring Braintree Client with JS v3 - encountering a null payment_method_nonce causing issues with form submission

I have successfully integrated Braintree into my Laravel 5.2 app using JS v2 client setup, but now I want to upgrade to v3. I have customized the code from the docs as follows: <form id="checkout-form" action="/checkout" method="post"> <div id= ...