Using app.router.navigate if go back I get undefined object

if I am using app.router.navigate to pass context to the next page as shown below then when i return back to this page i was before the object array i was having in memory is undefined after i go back. Console error: undefined object…

also the router get lost in this case to go back…

In the page of hotels I have the array all_hotels using handlebars I print all list of hotels…
and when I want to see a specific hotel i do:

Method:

  viewHotel : function (hotel,n) {

          app.router.navigate('/hotel-details/', {
                                reloadCurrent: false,
                                pushState: false,
                                context: {
                                    hotel_results: hotel,
                                }
          });

in hotel-details page i use the link back to return:

      <a href="#" class="link back">

then the all_hotels array is undefined when back…

how to use app.router.navigate propertly for not getting this undefined error in the console when returning back the that page?

any quick solution…for not getting undefined?

1 Like

Hey DEV,

where do you define this variable?

hotel

Try live code in https://jsfiddle.net/jhowjhoe/tynqcuwm/

hotel is defined in a previous page when i look for hotels in a location! after ajax request then I pass the json object array called hotel to the next page containing the list of hotels and then when i click on a particular hotel to see the details and I go back to the previous page then the list of hotels primary created return undefined and then error in the console and i cannot go back anymore…

I think after the three nested level of pages… the router kills the second page! I also try to put a form in the first page with a input value, then I go next passing the json object to the second page and i go back everything is fine, but if i go to the third page from the second and go back to the first page, then the first page show empty the form field value again… it is reseted… i think the same happening with the problem above but for a json object undefined…

trying to figure it out the router behaviour to find the problem …

you need to go deeper one page calls the second and second call the third and you will see the undefined on page 1 when going back…

the other thing will be doing the ping pong method send the context of 1 page to second one and then to the third and when back sending it back again for not getting undefined object but i think it should be not undefined if already existed with no need to pass to and back the context all the time between pages…

i am trying to see a better solution…