Node/Express Issue with redirect [SOLVED]

I’ve this project where if I scroll down the list of items on the index page, and say, I’m in te middle of the list, and press add item to cart (“agregar al pedido”), it adds the item and then scrolls back to same position, so I don’t have to scroll down all over again.

I achieve that with this code-

window.addEventListener('scroll', function() {
    localStorage.setItem('scrollPosition', cwindow.scrollY);
  }, false);
  window.addEventListener('load', function() {
    if(localStorage.getItem('scrollPosition') !== null)
      window.scrollTo(0, localStorage.getItem('scrollPosition'));
  }, false);

But if you search for an item (you can test with “carpeta”) and add one to the cart, it returns to the main index page. And you have to start all over again. How can I prevent that?

You can check the source here.

Actually, I’ve been thinking it has to do with the redirect after adding to cart, not the DOM manipulation.

This is the index route that contains the search-

router.get('/', isLoggedIn, function (req, res, next) {
  var noMatch = null;  
  var successMsg = req.flash('success')[0];  
  if(req.query.search) {
    var regex = new RegExp(escapeRegex(req.query.search), 'gi');
    Product.find({description: regex}, function(err, products) {      
      if(products.length === 0) {
         noMatch = 'Ese producto no se encuentra. Pruebe con otra palabra, o haga click en "Falta Producto!"';
      }
      res.render("shop/index", {title: 'eStationery', products: products, successMsg: successMsg, noMessages: !successMsg, user: req.user, noMatch: noMatch});
    });
  } else {
    Product.find(function(err, products) {
      res.render("shop/index", {title: 'eStationery', products: products, successMsg: successMsg, noMessages: !successMsg, user: req.user, noMatch: noMatch});
    });
  }
});

So, basically first would search for the query, or show all products by defaullt.

But, everytime I click on an item to be added to the cart, it redirects to '/' -

router.get('/add-to-cart/:id', isLoggedIn, function(req, res, next) {  
  var productId = req.params.id;  
  var cart = new Cart(req.session.cart ? req.session.cart : {});
  Product.findById(productId, function(err, product) {
    if (err) {
      return res.redirect('/');
    }        
    Product.findByIdAndUpdate(req.params.id, {$set: {tempStock: product.tempStock + 1, stock: product.stock -1}}, function(err, updatedProduct) {
      if (err) {
        return res.redirect('/');
      } 
    });
    cart.add(product, product.id);
    req.flash('success', 'Producto agregado al carrito.');
    req.session.cart = cart;
    res.redirect("/");
  });
});

So, I’m thinking I should tell the app to remain on the current query if there is one, no? something like 'res.redirect(/?search=value)' ?
Am I close?

Edit and solution: no, I was not.
I just had to change the redirect from "/" to "back", so after sending the item -which goes as /add-to-cart/:id added to the cart, it would just return to the same page.