Ionic-framework: Should the navPush directive default to not allow pushing the same page multiple times?

Created on 17 Nov 2016  路  7Comments  路  Source: ionic-team/ionic-framework

I feel like it should be a built-in feature within the directive. I would like to customize the directive right now, but I'm not sure how to. One workaround I thought up to fix this is to disable the button for the navPush when currentpage = the page it points to. But that's kinda hacky.

Most helpful comment

I disagree.

Here's a scenario that is not an edge case:

ProductDetailPage shows a product and a list of related products. The user can tap a related product to show it, and it would also use the ProductDetailPage.

It's a perfectly valid use-case and it would be pretty confusing just updating the page with the tapped related product + you would lose the ability to nagivate back using the back button.

Why do you need the framework to protect you from pushing a page multiple times anyway? It seems pretty simple to avoid pushing the same page multiple times if you don't want to.

All 7 comments

In my opinion, it should be the developers responsibility to decide if pushing the same page several times, make sense.
I could easily imagine a scenario where you actually would want to push the same Page already displayed, but passing different parameters via NavParams to show another set of data.

That's probably not a regular use case though right? I would imagine there would be a way to update the data already displayed on the view. Making the user push a view to see updated data seems wrong.

If anything, most developers would NOT want the feature of being able to push the same page over and over again. Regular navigation trumps edge cases.

I disagree.

Here's a scenario that is not an edge case:

ProductDetailPage shows a product and a list of related products. The user can tap a related product to show it, and it would also use the ProductDetailPage.

It's a perfectly valid use-case and it would be pretty confusing just updating the page with the tapped related product + you would lose the ability to nagivate back using the back button.

Why do you need the framework to protect you from pushing a page multiple times anyway? It seems pretty simple to avoid pushing the same page multiple times if you don't want to.

[navPush] is a very simple directive, and it is your responsibility to do the right thing.

You can set the value to null, to disable it.

<button [navPush]="page">
this.page = null;

@manucorporat Setting this.page = null still allows me to navigate to the page, strangely. At first I thought it was because I was generating a new instance of the button, but even when I go back to the root of the stack, it would still allow me to navigate it. Can you please further assist?

@kamok run ionic info and post the result. Also, can you provide a minimum source code that reproduces the issue?

Was this page helpful?
0 / 5 - 0 ratings