Wix.Location to Dynamic Pages

When the user clicks on the Login button I’d like them to be directed to their dynamic Member page:

Here is the page code:

import wixLocation from ‘wix-location’;

$w.onReady( function (){
$w(‘#loginNow’).onClick( function (){
let email = $w(‘#loginEmail’).value;
let password = $w(‘#loginPassword’).value;
wixUsers.login(email,password)
.then(()=>{
wixLocation.to(‘/Member/${_id}’);
})
})
})

Here is the page settings for the dynamic page:

Here is the ID field in the Member database:

The login button seems to work if it’s directed to a different page. For example if I want to send the user to the shop page:

wixLocation.to(‘/shop’); <— This seems to work
wixLocation.to(‘/Member/${_id}’); <— This does not work :frowning:

Any help is greatly appreciated!

FD

Hi Josh,

If you create your own member area according to this tutorial, you miss the line that get the current user ID.

import wixLocation from 'wix-location'; 

 $w.onReady(function(){       
     $w('#loginNow').onClick(function (){      
             let email = $w('#loginEmail').value;      
             let password = $w('#loginPassword').value;           
             wixUsers.login(email,password)           
             then(()=>{     
                    wixLocation.to(`/Members/${wixUsers.currentUser.id}`);           
        })     
    })  
   })   

Best,
Sapir

Hey there,

I am trying to create the same thing. However, the URL does not accept special characters (% or $). Has anyone had this issue? If so, how do I get around it? This is my first time building a website so I am definitely open to any suggestions, besides hiring someone to do it for me.

Hi ! try his →

  1. Query and get the _id field from the database.
wixData.query("UserProfileData")
  .eq("userId", userId)
  .find()
  .then( (results) => {
 if(results.items.length > 0) {
 let items1 =  results.items[0]._id;
 let id = `${items1}`
 

     wixLocation.to(`/Member/${items1}`);
     }
     });

@ajithkrr Thank you for your suggestion! I tried but it did not work. It says the field parameters need to be spaced differently.

Hi !!
In your database, you should have a field of url like this →

Click on the ‘properties’ and get the field key…

Get the field key and →

wixData.query("UserProfileData")
  .eq("userId", userId)
  .find()
  .then( (results) => {
 if(results.items.length > 0) {
let items = results.items[0]['link-userprofiledata-title'];  //field key 

console.log("let items be   " + items);
 let id = `${items}`
      console.log("let id is " + id);

    wixLocation.to(`${items}`);
 }
});

If this also dosen’t work, share your code…

@ajithkrr Hiya! I was wondering if you had a code that redirects current user to a dynamic page?

did you ever figure out a solution? i’ve been looking all over

did you ever figure out a solution? i’ve been looking all over

It would be better to open your own post, with your own issue-topic.
Explain your problematic situation, as goog as possible, to get some answers.

You can link this post to your own.