'Fire GTM dataayer variable on specific history change

I am using react-gtm-module in my react project to add Google Tag Manager in my project. As of now i was firing the dataLayer variable whereever required by the following code

 window.dataLayer = window.dataLayer || []
          window.dataLayer.push({
          Car_NewUser_Create: 'Yes'
 })

but now there is a special case where i need to fire this same varaible "Car_NewUser_Create" when we go from "/simulcao" route to "/pacotes" route.

There is a configuration in GTM for history triger change that detects every change in history route, but for this specfic route change i need to pass this variable and I am not able to find any source on how to achieve it.

Thanks !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source