Checking the routes in vue for accuracy

I have multiple routes set on a single page, and I am looking to validate only one specific route using the following code:

beforeRouteEnter(to, from, next) {
      
    
      if(firstString=='a'||firstString=='A'){
        if(parseInt(substring1) > 219028 && parseInt(substring1) < 386817){
  console.log("Valid")
      }
      else{
        alert("Invalid Seat No...!!")
          next({
            path: '/'
          });
          this.$refs.seatno1.focus();
        }

    },
<router-link :to="'institute_details/' + seatno " class="btn btn-success" >
                  <span v-on:click.capture="validateData">LINK</span>
                </router-link>



<router-link :to="'institute_details/' + agriculture"  data-toggle="tooltip" title="agri" data-placement="right" class="btn btn-danger">Agri</router-link> 

I specifically need to validate "'institute_details/' + seatno".

Answer №1

To enhance your route syntax, consider utilizing regex or dynamic patterns to match specific addresses, which will cater to most scenarios.

In a straightforward example like this, you can access the parameter within the component using this.$route.params.location.

new VueRouter({
  routes: [
    { path: 'institute_details/:location', component: somePage }
  ]
})

For more in-depth information (including advanced regex techniques), visit: https://router.vuejs.org/guide/essentials/dynamic-matching.html

Furthermore, you have the option to implement navigation guards either globally or at the component level for more sophisticated testing and the ability to reject navigation if necessary by calling next(false).

beforeRouteEnter (to, from, next) {
    if (to.params.location === 'you-shall-not-pass') {
        next(false);
    }
    else {
        next();
    }
}

Refer to: https://router.vuejs.org/guide/advanced/navigation-guards.html

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

Quickly browse through the options (Vuex, routing) and modify the routing based on the selected value from the

Seeking advice on dynamically changing routing details in a search component based on user selection from a dropdown menu. Home.vue Components <h4>Search for {{searchObj.whatSearch}}</h4> <input type="text" placeholder=& ...

The swipe function of Hammer.js is unable to detect gestures on a rotated iframe

After creating a rotated iframe on the page using CSS transforms, I attempted to implement swipe events within the iframe. body.rotate iframe { transform: rotate(90deg); transform-origin: top right; position: absolute; t ...

Struggling with displaying MySQL data in JSON format using Highcharts

Currently, I am attempting to display data from a PHP file on an area graph by using the example found here. Initially, all the data was commented out before being passed to the array. Now, my focus is solely on displaying one portion of the data. I suspec ...

Applying a new class to a child element and observing its impact on the parent element

Whenever I hover over an element, I want to add a class specifically to that element using jQuery. However, the issue is that when I hover over any element, the class gets added to all parent elements as well. Can someone please advise on how I can ensure ...

Retrieve an item from the Ionic Firebase database

My current challenge is retrieving data from the Firebase database. user-service.ts getProfile(){ try {; return this.afDatabse.object(`profile/${this.afAuth.auth.currentUser.uid}`); } catch (e) { console.log(e); } } c ...

Iterate over a specified range of elements within a list using jQuery

Hello everyone, I am new to JQuery and facing a challenge. I am attempting to iterate through a list in jQuery that was sent from a servlet to JSP, starting from a specific index to another one. However, my attempts have been unsuccessful so far. Here is ...

TypeORM Error: Trying to access property 'findOne' of an undefined object

I've been working on implementing TypeORM with Typescript, and I have encountered an issue while trying to create a service that extends the TypeORM repository: export class UserService extends Repository<User> { // ... other service methods ...

The issue of array sorting, specifically the function(a, b) {return b.value - a.value), is causing some

I am struggling to retrieve data from firebase and sort them according to the field 'overallScore' in descending order. Despite following suggestions like using array.sort(function(a, b) {return b.value - a.value), I have not been successful in s ...

Activate the component once all data is prepared

I am currently utilizing React along with Redux to manage my state. In this specific scenario, I have a class that includes mapStateToProps and mapDispatchToProps. class EnigmaPage extends Component { constructor(props){ super(props); } ...

Display the data from the database in a label based on the selection made in the combo box

In an attempt to pass values into a label based on the selected option from a combobox, let's say if I choose A, the label should display 1 and if I select B, it should display 2. Here is my code: kota.php: $conn = mysql_connect('localhost&apo ...

Vue.js: Calculated property in a JavaScript object

Within my Vue.js component, I have a data property structured like so: elementData{ amount: '', unit_price: '', total: '', } I am trying to make the "total" property a computed property in order to eliminate the need f ...

Different Option for Ajax/Json Data Instead of Using Multiple Jquery Append Operations

I am working on a complex data-driven application that heavily relies on Ajax and Javascript. As the amount of data returned for certain value selections increases, the application is starting to struggle. This is more of a brainstorming session than a q ...

Is it possible to automatically redirect to a different URL if the server is running slow when clicking?

Is it possible to utilize Javascript, AJAX, or another client-side technology to automatically redirect the user to a different URL if the initial URL is slow to respond when clicked on? For example, if a link redirects to URL1 and there is no response fr ...

The save and cancel button are experiencing technical difficulties and are currently non-functional

After creating an application in AngularJS to add and remove popup modals, I encountered an issue where the saved data was returning as undefined, and the cancel functionality was not working properly. Check out the JSFIDDLE here If anyone has any soluti ...

Can an object serve as a property name for another object?

Can this be achieved using JavaScript? I'm attempting to assign the property name of an object as a "HTMLInputElement": var el = $('#something').get(0), obj = {}; obj[el] = 'some random data'; Unfortunately, it ...

Issue with ng-model causing incorrect variable binding

My issue lies with a variable that I have connected to a select input through the use of ng-model. Strangely, the variable seems to not update with the correct data and retains the value assigned to it during initialization. I have a similar setup elsewhe ...

Retrieving data in [slug].js using Reactjs

I am currently working on a project in Reactjs utilizing the "nextjs" framework. I have successfully managed to retrieve data (specific blog details) based on the slug([slug.js]). However, I now need to display data from all other blogs within the same c ...

Rearranging arrays

If I have an array structured like this: var playlist = [ {artist:"Herbie Hancock", title:"Thrust"}, {artist:"Lalo Schifrin", title:"Shifting Gears"}, {artist:"Faze-O", title:"Riding High"} ]; Is there a way to rearrange the elements? For in ...

Python Eve encountering WSGI issue [Errno 32] causing a broken pipe during an Ajax call

As I operate a simplistic wsgi server, from run import app if __name__ == "__main__": app.run(threaded=True, debug=True) When I send a get request to the server, it responds with a 200 message but no data. An error message is displayed: Error on r ...

Expandable drop-down menu upon clicking

Having trouble creating a dropdown menu on click? Check out the real site I'm working on: . The menu turns into a single button under 736px width, but it's buggy on mobile devices. When clicked on a phone, it automatically redirects to the last b ...