# How to get the current active page name as a string on any given time from Navigation?

**URL:** <https://forums.fusetools.com/t/how-to-get-the-current-active-page-name-as-a-string-on-any-given-time-from-navigation/4339>\
**Category:** General\
**Created:** [February 10, 2018, 4:04pm UTC](https://forums.fusetools.com/t/how-to-get-the-current-active-page-name-as-a-string-on-any-given-time-from-navigation/4339 "2018-02-10T16:04:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matti\_Tihverainen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/matti_tihverainen/32/684_2.png) [@Matti\_Tihverainen](https://forums.fusetools.com/u/Matti_Tihverainen)\
**Post date:** [February 10, 2018, 4:04pm UTC](https://forums.fusetools.com/t/how-to-get-the-current-active-page-name-as-a-string-on-any-given-time-from-navigation/4339/1 "2018-02-10T16:04:57Z")

</div>

Hello! For PageControl there’s ActiveIndex in order to get the current page in view (via Observable), but how can this be done with Navigator? In the example below I could get the current page by using a global string variable and changing it in router.push (or Activated for every page) and OnGoBack, but that’s more work than simply getting it straight from the UX via Observable for example.

```auto
<App>
  <JavaScript>

    module.exports = {
      gotoGreenPage: function() {router.push("greenPage");},
      gotoRedPage: function() {router.push("redPage");},
      logCurrentPath: function() {
        console.log("Current path: ?");
      }
    };

  </JavaScript>
  <Router ux:Name="router" />
  <Navigator ux:Name="navigator" DefaultPath="yellowPage">
    <Page ux:Name="yellowPage" Background="Yellow">
      <Button Text="Goto green page" Background="Black" Width="200" Height="100" Alignment="Center" Y="-25%" Clicked="{gotoGreenPage}" />
      <Button Text="Log current path" Background="Black" Width="200" Height="100" Alignment="Center" Clicked="{logCurrentPath}" />
      <Button Text="Goto red page" Background="Black" Width="200" Height="100" Alignment="Center" Y="25%" Clicked="{gotoRedPage}" />
    </Page>
    <Page ux:Name="greenPage" Background="Green">
      <Button Text="Log current path" Background="Black" Width="200" Height="100" Alignment="Center" Clicked="{logCurrentPath}" />
    </Page>
    <Page ux:Name="redPage" Background="Red">
      <Button Text="Log current path" Background="Black" Width="200" Height="100" Alignment="Center" Clicked="{logCurrentPath}" />
    </Page>
  </Navigator>
</App>

```

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [February 12, 2018, 6:57am UTC](https://forums.fusetools.com/t/how-to-get-the-current-active-page-name-as-a-string-on-any-given-time-from-navigation/4339/2 "2018-02-12T06:57:52Z")

</div>

Perhaps [router.getRoute()](https://www.fusetools.com/docs/fuse/navigation/router/getroute_eca3d620) could be of help?

---

<div class="post-metadata">

**Author:** ![Matti\_Tihverainen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/matti_tihverainen/32/684_2.png) [@Matti\_Tihverainen](https://forums.fusetools.com/u/Matti_Tihverainen)\
**Post date:** [February 12, 2018, 7:10am UTC](https://forums.fusetools.com/t/how-to-get-the-current-active-page-name-as-a-string-on-any-given-time-from-navigation/4339/3 "2018-02-12T07:10:50Z")

</div>

Thanks again Uldis!

---

<div class="post-metadata">

**Author:** ![Matti\_Tihverainen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/matti_tihverainen/32/684_2.png) [@Matti\_Tihverainen](https://forums.fusetools.com/u/Matti_Tihverainen)\
**Post date:** [February 13, 2018, 7:56am UTC](https://forums.fusetools.com/t/how-to-get-the-current-active-page-name-as-a-string-on-any-given-time-from-navigation/4339/4 "2018-02-13T07:56:01Z")

</div>

Hello! I’m trying to use getRoute in OnBackButton with a Handler, but the problem is that when that Handler fires, getRoute returns the page which we are about to show. Is there a way to get the previous page instead of the upcoming?

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [February 13, 2018, 8:42am UTC](https://forums.fusetools.com/t/how-to-get-the-current-active-page-name-as-a-string-on-any-given-time-from-navigation/4339/5 "2018-02-13T08:42:47Z")

</div>

I don’t think so, because your `getRoute` call happens after the back button was pressed, so the navigation action has already happened.

Can’t help but ask: why do you need this?

---

<div class="post-metadata">

**Author:** ![Matti\_Tihverainen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/matti_tihverainen/32/684_2.png) [@Matti\_Tihverainen](https://forums.fusetools.com/u/Matti_Tihverainen)\
**Post date:** [February 13, 2018, 8:51am UTC](https://forums.fusetools.com/t/how-to-get-the-current-active-page-name-as-a-string-on-any-given-time-from-navigation/4339/6 "2018-02-13T08:51:33Z")

</div>

I’m trying to detect the following:

1. User is in the yellowPage (the main page).
2. User taps the back button.  
In this case the app should close on Android (using a custom Uno class for this). The problem is that if I’m in green or red page and press the back button, OnBackButton handler returns also the yellowPage from the router. One solution could be that I create a global string variable “previous\_page” and change this in Activated.

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [February 13, 2018, 9:02am UTC](https://forums.fusetools.com/t/how-to-get-the-current-active-page-name-as-a-string-on-any-given-time-from-navigation/4339/7 "2018-02-13T09:02:48Z")

</div>

You could create a global `shouldClose` or `canGoBack` boolean, and change the value of it from the `Activated` trigger on whatever pages it’s appropriate. Or use [WhileCanGoBack](https://www.fusetools.com/docs/fuse/navigation/whilecangoback), optionally, with `Invert="true"`.

---

<div class="post-metadata">

**Author:** ![Matti\_Tihverainen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/matti_tihverainen/32/684_2.png) [@Matti\_Tihverainen](https://forums.fusetools.com/u/Matti_Tihverainen)\
**Post date:** [February 13, 2018, 9:15am UTC](https://forums.fusetools.com/t/how-to-get-the-current-active-page-name-as-a-string-on-any-given-time-from-navigation/4339/8 "2018-02-13T09:15:34Z")

</div>

Thanks Uldis!
