Editing the Navigation.Href Property

I am trying to do a thing where I need to edit the Navbar link of my app with the current ID of a customer.

I’ve got the ID being saved in store, and can access it in app.js, and can access the router.navigation.href property, but I’m having trouble editing the route to get it to update and then send the user back to that customer after clicking off that page.

Here’s my route definition:

`
{

    route: 'customer/:debtor_id?/:inv_num?/:show_closed_inv_num?',

    name: 'customer',

    moduleId: PLATFORM.moduleName('customer'),

    nav: true,

    href: 'customer',

    title: 'Customer',
  },

`

this is where I attempt to update the router’s href:

`
activate(params)

{

console.log('navigation', this.router);

console.log('state', this.state);

/*

console.log('this', this);

console.log('params', params);

*/

this.consolEvent = this.ea.subscribe('router:navigation:complete', async event => {

  console.log('APP ATTACHED', this.state);

  if (this.state.customerObj)

  {

    this.customerNav = this.router.navigation[1];
    this.customerNav.href = this.customerNav.href + '/?debtor_id:' + this.state.customerObj.debtor_id;

    this.router.navigation[1] = this.customerNav;

  }

});

}
`

1 Like

I’m not really sure why it’s being done this way, and what is failing. But this line looks wrong:

    this.customerNav.href = this.customerNav.href + '/?debtor_id:' + this.state.customerObj.debtor_id;

Shouldn’t it be:

    this.customerNav.href = this.customerNav.href + '/?debtor_id=' + this.state.customerObj.debtor_id;

: should be =

I tried that, and it still bounced me to ‘customer’ which is what the href in the <home> module is defined as.

Is there a better way to do what I’m trying to do?

Basically I just need to update that link to reflect whatever the current Debtor Id is and direct the client back to that customer from any page until they click on a new customer.

I figured out what I needed to do.

I accessed the document.getElementById('customerLink').getAttribute('href') to get the link, and then modified that link.

By creating the link there, I was able to adjust it as needed to update the link to reflect the current customer’s Id.

And the url just needed to be customer/[debtor_id] without the ?debtor_id= .

The router was the wrong way to go.

Thanks for the help!