2
votes

I am trying to get the router.navigateBack function working correctly using Durandal 2.0.1.

I have a viewmodel that can create an entity that we'll call lead. After creating a new lead I want to replace the uri so that it has the edit lead route instead of the create lead route and also replace it in the history. I call the following function after save:

router.navigate('#lead/' + vm.lead().id(), { replace: true, trigger: false });

here is the route description in my config file

{
    route: 'lead(/:leadId)',
    moduleId: 'lead/lead'
}

Then afterwards when I call

router.navigateBack();

It navigates to the expected route but always causes a full page refresh. I am trying to avoid the full page refresh and simply navigate as usual.

In durandal 1.0 I used to just call

router.replaceLocation();

To accomplish this same task and it would work well. I'm wondering if I'm missing something here.

1

1 Answers

1
votes

Try the following:

var leadId = vm.lead.peek().id.peek();
router.navigate('#lead/' + leadId, { replace: true, trigger: false });

I believe your observable has a dependency that's causing a complete recalculation. We can use Knockout's peek() to obtain a value without creating a dependency.