Javascript function in /url page not working after using history.push(/url) onlick

This is my js function to hide/show login password, but when i redirect to login page from another page using history.push(/login) the function doesn't work. And when putting (/login) in the href in the tag, it works. How can i fix this? Thank you. Note: I dont want refresh my website so i dont want to use href or forceRefresh.

var showPassword = function () {
  $('.show-pass').click(function (e) {
    var grand = $(this).parent();
    var type = $("#show-password", $(grand)).attr('type');
    switch (type) {
      case 'password':
          $("#show-password", $(grand)).attr('type', 'text');
          $(".icon-invisible", $(grand)).removeClass('icon-invisible').addClass('icon-visible');
      case 'text':
          $("#show-password", $(grand)).attr('type', 'password');
          $(".icon-visible", $(grand)).removeClass('icon-visible').addClass('icon-invisible');

a part of my router containing /login

<Route  path="/login" component={SignIn}/>

Read more here:

Content Attribution

This content was originally published by Trần Ngọc Văn at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: