# Switching to ApmRoute changes the behavior of the application

**URL:** <https://discuss.elastic.co/t/switching-to-apmroute-changes-the-behavior-of-the-application/252795>\
**Category:** APM\
**Tags:** rum\
**Created:** [October 21, 2020, 7:59am UTC](https://discuss.elastic.co/t/switching-to-apmroute-changes-the-behavior-of-the-application/252795 "2020-10-21T07:59:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kocsis1david](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@kocsis1david](https://discuss.elastic.co/u/kocsis1david)\
**Post date:** [October 21, 2020, 7:59am UTC](https://discuss.elastic.co/t/switching-to-apmroute-changes-the-behavior-of-the-application/252795/1 "2020-10-21T07:59:10Z")

</div>

I've created an example to demonstrate the issue:  
[https://github.com/kocsis1david/apm-route-bug](https://github.com/kocsis1david/apm-route-bug)

If you use the simple `Route`, the number will increase when switching between paths, see this [video](https://drive.google.com/file/d/1JvOa7GBbvYSvuYEJxqzI4v96OepnSmgJ/view). But if you replace `Route` to `ApmRoute`, the number will always be `1`. The `ApmRoute` is already imported so it's easy to replace to it in the example.

The cause of the problem seems to be that hooks lose their states when the route is changed, and `useState` will reset the `counter` to its default value.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 11, 2020, 3:59am UTC](https://discuss.elastic.co/t/switching-to-apmroute-changes-the-behavior-of-the-application/252795/2 "2020-11-11T03:59:19Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
