wix.Location.to are not working

Hello Wix.com,

I would like the visitor to be re-directed to different websites, so I assigned each button in the picture with different location:


Here are the codes I wrote:

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady(()=>{
if (wixUsers.currentUser.loggedIn){
$w(‘#loginButton’).label=“Logout”;
$w(‘#button39’).hide();
$w(‘#button10’).hide();
$w(‘#box11’).hide();
$w(‘#ProfileButton’).show();
$w(‘#profileButton’).show();
$w(‘#CoffeeButton’).show()}

else {
$w(‘#loginButton’).label=“Login/Register”;
$w(‘#button39’).show();
$w(‘#button10’).show();
$w(‘#box11’).show();
$w(‘#ProfileButton’).show();
$w(‘#profileButton’).hide();
$w(‘#CoffeeButton’).hide()}
});

export function ProfileButton_click(){
if (wixUsers.currentUser.loggedIn){
wixUsers.logout()
.then(()=>{
$w(‘#loginButton’).label=“Login/Register”;
$w(‘#button39’).show();
$w(‘#button10’).show();
$w(‘#box11’).show();
$w(‘#ProfileButton’).show();
$w(‘#profileButton’).hide();
$w(‘#CoffeeButton’).hide();
wixLocation.to(‘/successfullogout’); //NOT WORKING
})
. catch ((err)=>{
console.log(err)})
}
else {
wixLocation.to(/login); //WORKING
}
}
export function loginButton_click(){
if (wixUsers.currentUser.loggedIn){
wixUsers.logout()
.then(()=>{
$w(‘#loginButton’).label=“Login/Register”;
$w(‘#button39’).show();
$w(‘#button10’).show();
$w(‘#box11’).show();
$w(‘#ProfileButton’).show();
$w(‘#profileButton’).hide();
$w(‘#CoffeeButton’).hide();
wixLocation.to(‘/successfullogout’); //NOT WORKING
})
. catch ((err)=>{
console.log(err)})
}
else {
wixLocation.to(/login); //WORKING
}
}
export function CoffeeButton_click(event) {
wixLocation.to(‘/Members/${wixUsers.currentUser.id}/’); //NOT WORKING
}
export function profileButton_click(event) {
wixLocation.to(‘/Members/${wixUsers.currentUser.id}/’); //NOT WORKING
}

Sadly, none wixLocation.to works. Can anyone help, please? Here is my site: https://www.elroblehomecare.com/login

Thanks,

Louise

when you want to embed parameters in your strings you cant use ‘’ to define the strings, you have to use `` (backticks)

Hi,

I’ve replaced the " with the backticks. However, the WixLocation.to still doesn’t work.

add a console log so your can see what the actual URL is, it will make it more easy to see what is going wrong, once you log the URL copy and paste it into a web browser see if it works, if not then modify the URL until it does work…

export function CoffeeButton_click(event) {
console.log(‘/Members/${ wixUsers.currentUser.id }/’)
wixLocation.to (‘/Members/${ wixUsers.currentUser.id }/’); //NOT WORKING }

also good idea to remove the code and just use strings when calling wixLocation:

export function CoffeeButton_click(event) {

let userId = ( wixUsers.currentUser.id );
console.log(userId);

console.log (“/Members/” + (userId) +“/”);
wixLocation.to (“/Members/” + (userId) +“/”); }