MEAG
MEAG

Reputation: 127

window.location.href in VUE 3 JS

I didn't get the issue here.

When I use

return window.location.href = 'https://www.google.com';

it works fine. However, if I use my string variable. It doesn't work.Reloads back to page.

return window.location.href = this.navigationURL;

Full code:-

 <table class="">
   <tr
     class="cursor-pointer"
        v-for="currentView in authenticationMethodsAvailable"
          :key="currentView.id"
            >
        <td class=""> (HERE)
   **<button type= "button" @click="authenticationChoice(currentView['name'])" >**
                <img
                  class="w-12 inline-block align-middle"
                  :src="showAuthenticationIcon(currentView['gitType'])"
                 
                />
              </button>
              </td>
            </tr>
          </table>

The function being triggered


    authenticationChoice(recieved) {
      this.$store.state.gitSourceAuthenticationChoice = recieved;

      this.$store.dispatch("gitSourceAuthenticationURL").then((response) => {
        this.navigationURL = response["oauth2_redirect"];
        console.log(this.navigationURL)
       
      });
    return this.navigationURL ;
  // return window.location.href = String(this.navigationURL);
    },

Upvotes: 2

Views: 9591

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

Remove the return which's breaking the code and move the code inside the then block as follows :

    authenticationChoice(recieved) {
      this.$store.state.gitSourceAuthenticationChoice = recieved;

      this.$store.dispatch("gitSourceAuthenticationURL").then((response) => {
        this.navigationURL = response["oauth2_redirect"];
        console.log(this.navigationURL)
       window.location.href = String(this.navigationURL);
      });
  
    },

Upvotes: 2

Related Questions