User input determines the path of Iron Route in Meteor

A requirement is to execute a function that prompts the user for input and then navigates to that specified value. For instance, if the inserted value is:

https://www.youtube.com/watch?v=_ZiN_NqT-Us

The intended destination URL should be:

download?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_ZiN_NqT-Us

I've attempted to retrieve the value using Set.session to retrieve the session in the Router, but it's not returning any value as expected.

Template.inputBar.events({
'click #download':function(event, template) {
var url = template.find('.url').value;
if (url.value != "") {
Session.set('url', url);
} 
else {
alert('paste link');
}
}
});

This will navigate to the provided value and trigger a call to the server:

Router.map(function(){
  this.route('frontPage', {path: '/'} );
  this.route('downloadLinks', {
  path: '/download?link=:url',
  data: function() {
          var url = Session.get('url');
          Meteor.call('command', url, function(error, result) {
          if(result.stdout) {
            console.log(result.stdout)
          }
          else {
            alert("Not supported site");
          }
        });
  }
  });
});

Answer №1

Visit the Router.go Documentation

Template.inputBar.events({
  'click #download':function(event, template) {
    var url = template.find('.url').value;
      if (url.value != "") {
        Router.go(url.value);
      } else {
        alert('please paste a link');
      }
    }
});

This function will direct you to the specified route.

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

Question: How can I use the jQuery datepicker to ensure that the selected date remains in the

I recently created a webpage using a combination of HTML, PHP, and jQuery. The PHP script is designed to load all data where the date matches the one selected in the text input field generated by the jQuery datepicker. However, I encountered a problem whe ...

Transmitting C# data to a JavaScript script through JSON serialization. Issue encountered: Character invalid

I'm facing an issue with sending data from my Entity Framework database to a JavaScript script on my webpage. Below is the snippet of code from my MVC Controller: public ActionResult Index() { var wordsToShow = db.Words.Where(w => w.O ...

Is it possible to convert the text.json file into a jQuery animation?

Looking to extract information from text.json and integrate it with my jquery.animation(). My goal is similar to the one demonstrated here. Instead of using "data" attributes like in that example, I want to parse the text based on the "ID" property as a k ...

Ensuring a radio button is pre-selected by default in React by passing in a prop

Assume I have a React function similar to this function Stars({handleStarClick, starClicked}) { if (starClicked === 3) { document.getElementById('star3').checked = true } return ( <div className="rate"> ...

How to retrieve the correct instance of "this" from a callback function within an array of functions nested inside an object

Trying to access the "helperFunction" from within a function in the "steps" array has been quite challenging. It seems that using "this" does not point to the correct object, and I have been struggling to find the right solution. const bannerAnimation = { ...

What is the best way to create a time delay between two consecutive desktop screenshot captures?

screenshot-desktop is a unique npm API that captures desktop screenshots and saves them upon request. However, I encounter the need to call the function three times with a 5-second delay between each call. Since this API works on promises, the calls are e ...

IE9 presents a frustrating issue where the jQuery select box value is returning as

I've been battling a bug for over 2 hours now. My javascript code is supposed to generate a two-level select box for tasks and subtasks from JSON data. However, I recently discovered that this code doesn't function properly on IE9, and possibly ...

Identify moving objects with react-beautiful-dnd

I've successfully implemented a draggable list using react-beautiful-dnd by following the tutorial. The result looked like this: You can find the code for this implementation here: https://github.com/DDavis1025/react-beautiful-dnd Now, I'm work ...

Discover the steps to capture the ajax initiation and completion events

In my application, I have numerous ajax requests. To display a loading symbol while these requests are in progress, I am utilizing jquery ajaxStart and ajaxStop methods. However, for some reason, they seem to not be functioning as expected. Despite searc ...

The webpack-concat-text-plugin "node" is not compatible

The concat-text-webpack-plugin is located deep within a package, and it throws errors when I have NextJS and Node 18. Error: The engine "node" is incompatible with this module. Expected version ">=8 <=16". Got "18.16.0" Error Found incompatible modul ...

What is the process for creating a widget that can be seamlessly integrated into someone’s website and hosted on your own site

In relation to this previous question. After researching JSONP and conducting some tests, I've realized that I am completely clueless about what I'm doing... What is required? I am developing a customer service tool for people to integrate in ...

How can you handle the "Request entity too large" error in Node.js to prevent the "PayloadTooLargeError" from occurring?

Is there a way to prevent PayloadTooLargeError from being exposed when handling large data in the body-parser middleware? Adding {limit: '50mb'} doesn't seem to fully address the issue, as an attacker could still send data slightly larger th ...

The style of the button label does not persist when onChange occurs

Encountered an interesting issue here. There is a button designed for selection purposes, similar to a select item. Here's the code snippet: <button class="btn btn-primary dropdown-toggle" style="width: 166%;" type="button" id="dropdownMe ...

Using Javascript libraries on a Chromebook: A comprehensive guide to getting started

Doing some coding on my chromebook and wondering if it's possible to download and utilize libraries such as jQuery. Would really appreciate any assistance with this! ...

Converting object values to strings is a common practice during JSON posting operations

I encountered an issue with a date object when sending it to a NodeJS server. While the object is still preserved, the time gets converted to a string during the process. Is there a way to prevent this conversion? I tried parsing the object but received an ...

Loading message displayed in web browsers by banner rotation system

I'm currently working on a banner rotator function that seems to be showing a "loading" message continuously while running. Here is the code snippet for reference: var banners = ['../Graphics/adv/1.gif','../Graphics/adv/2.jpg']; / ...

Node.js Express is successfully receiving messages from the WebSocket server but encountering difficulties when attempting to send them out

My setup involves websockets with AWS API Gateway, an EC2 instance running Node.js and Express with WS websockets. I can send a message from wscat to the API Gateway WSS URL and it shows up in the EC2 instance. However, when I send a message from the EC2 i ...

creating reactive images with Vue

The original code utilized an image in a menu as shown below: <img :alt="$t('more')" class="mobile-plus-content visible-xs" src="../../../assets/img/plus79.png" /> This results in: src="data:image/png;base64,the image" I made a mo ...

Leverage the power of Angular and Node.js to dynamically generate and configure a new subdomain on an

Currently, I am tackling a project that involves generating sub domains dynamically based on the prefixes entered by users on my website. While everything is functioning properly on my localhost using diet.js and express-subdomain, errors are being encount ...

Do I have to include reject() in the executor when using promises in express.js?

If we choose not to handle rejection, is it necessary to include the reject parameter in the promise executor? For example: new Promise((res) => { res(a); }) ...