# Reusing an Existing View Model

**URL:** <https://discourse.aurelia.io/t/reusing-an-existing-view-model/3154>\
**Category:** Framework Knowledge\
**Created:** [January 13, 2020, 5:21pm UTC](https://discourse.aurelia.io/t/reusing-an-existing-view-model/3154 "2020-01-13T17:21:50Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![huochunpeng](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@huochunpeng](https://discourse.aurelia.io/u/huochunpeng)\
**Post date:** [January 13, 2020, 9:35pm UTC](https://discourse.aurelia.io/t/reusing-an-existing-view-model/3154/3 "2020-01-13T21:35:49Z")

</div>

To be clear

```auto
export const determineActivationStrategy = (
  currentNavInstruction: NavigationInstruction,
  prevViewPortInstruction: ViewPortInstruction,
  newViewPortConfig: RouteConfig | ViewPortInstruction,
  // indicates whether there is difference between old and new url params
  hasNewParams: boolean,
  forceLifecycleMinimum?: boolean
): ActivationStrategyType => {

  let newInstructionConfig = currentNavInstruction.config;
  let prevViewPortViewModel = prevViewPortInstruction.component.viewModel;
  let viewPortPlanStrategy: ActivationStrategyType;

  if (prevViewPortInstruction.moduleId !== newViewPortConfig.moduleId) {
// different view-model, use "replace".
    viewPortPlanStrategy = InternalActivationStrategy.Replace;
  } else if ('determineActivationStrategy' in prevViewPortViewModel) {
// when you defined determineActivationStrategy() in view-model
    viewPortPlanStrategy = prevViewPortViewModel.determineActivationStrategy(...currentNavInstruction.lifecycleArgs);
  } else if (newInstructionConfig.activationStrategy) {
// when you define activationStrategy in route config like
// { route: ..., moduleId: ..., activationStrategy: 'replace'}
    viewPortPlanStrategy = newInstructionConfig.activationStrategy;
  } else if (hasNewParams || forceLifecycleMinimum) {
// when you navigate from product/a to product/b for a route defined
// with params like product/:id
// use invoke-lifecycle
    viewPortPlanStrategy = InternalActivationStrategy.InvokeLifecycle;
  } else {
// default to no-change
    viewPortPlanStrategy = InternalActivationStrategy.NoChange;
  }
  return viewPortPlanStrategy;
};

```

---

_[View the full topic](https://discourse.aurelia.io/t/reusing-an-existing-view-model/3154)._
