Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$previous-page not storing params #126

Open
rmdydo opened this issue Apr 30, 2016 · 10 comments
Open

$previous-page not storing params #126

rmdydo opened this issue Apr 30, 2016 · 10 comments

Comments

@rmdydo
Copy link

rmdydo commented Apr 30, 2016

I have a simple app with three views: list (#!/list) -> detail (#!/list/:id) -> review (#!/review/:id) and the detail/review views have back buttons that use $previous-page. The first time I navigate from list -> detail -> review and use the back button to get to the list, everything works correctly. Any attempt to do this navigation flow for any other list items does not work because the back button replaces the :id with the :id from the first navigation. So if I first navigate to :id=2, any time I hit the back button on the review or detail views, it will take be back to :id=2 event if the current :id was something else. I did some debugging and it appears that the onRoute function only checks the page name and only adds it with the params to history the first time the view is navigated to. Is my navigation flow unsupported or is this a bug?
Thanks

@John-Henrique
Copy link

Are you using others frameworks? Because Phonon we use #!list/12 (using your example to /list/:id)

@rmdydo
Copy link
Author

rmdydo commented Apr 30, 2016

Only riot, yes that is actually what my urls look like I just excluded it to keep the example simple. I edited the original question.

@rmdydo
Copy link
Author

rmdydo commented May 3, 2016

@John-Henrique Is this navigation flow unsupported with $previous-page? Or is there a different url structure that I should use to achieve something similar? I can provide a sample app if that would be helpful.

@qathom
Copy link
Contributor

qathom commented May 5, 2016

HI @rmdydo,

Thank you for sharing your case.
I am not sure to understand it perfectly, but I think it is better that you use changePage programatically or setting the active (current) id in your view model like the following:

<button class="button" data-navigation="list/{ currentId }">Back for { currentId }</button> 
...
<script>
    this.currentId = 0

    var self = this
    this.on('hashchanged', function(id) {
         self.currentId = id
         self.update()
    })
</script>

As you say, Phonon takes the last route from history.
Furthermore, I think that it is more interesting (and logical?) to work with Riot tags in order to achieve your app logic. For example, you will need to retrieve the current ID at anytime and this should be done with tags.

What do you think about nested tags?

<app> => contains global data
    <view1> => contains data for view1 and inherits global data
    <view2> => contains data for view2 and inherits global data
</app>

@qathom qathom added the question label May 5, 2016
@gRegorLove
Copy link

I just came across the same thing.

I browse to:
#!category/1
=> #!product/2.

Clicking back takes me to #!category/1.

If I go back home and browse to:
#!category/2
=> #!product/3

Clicking back takes me to #!category/1 at this point, instead of #!category/2

I'm not working with Riot or other framework; just Cordova + Phonon.

@John-Henrique
Copy link

@gRegorLove with me too...

@gRegorLove
Copy link

I'll try the way of storing the current category ID; that may be more useful anyway since I can return to the category from more than 1 page away (e.g. navigate all the way to the shopping cart, button to return to the category).

@rmdydo
Copy link
Author

rmdydo commented May 12, 2016

@qathom Thanks, your solution works for me. However, from my perspective this behavior still looks like a bug and I would not naturally expect it to function this way. I would expect $previous-page to match the functionality of a browser back button and it does not currently do this. But my issue is resolved with your solution so its up to you to determine if this is in fact a bug or not. Thanks!

@rmdydo
Copy link
Author

rmdydo commented May 12, 2016

@qathom Actually, your solution only works for an html back button but the Android native back button still goes back to the first page that was ever navigated to, same as @gRegorLove demonstrated as well.

@qathom
Copy link
Contributor

qathom commented Jul 19, 2016

Hi @rmdydo,

It looks more like a bug.
I'll run more tests!

@qathom qathom added the bug label Jul 19, 2016
@qathom qathom added the v1 label Jul 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants