[SOLVED] Push nav params, not page


#1

Is there a way to update the parameters of a route without pushing a new page on to the stack?

Scenario: I have a page with a slider of images with a URI of /photo/:photo_id. When the user swipes to a new photo, I’d like to update the current photo_id parameter without pushing a new page. However, it doesn’t seem like there is a way to push parameters without a page in the NavController API.

What is the best way to achieve this?


#2

Instead of using any ionic component, I simply used history.replaceState.

I added the following to my page controller:

onSlideChange() {
    let currentIndex = this.slider.getActiveIndex()
    let hash = window.location.hash.split('/')
    hash.pop()
    history.replaceState(null, 'My page', hash.join('/') + '/' + currentIndex)
}

If the user navigates back, either with a hardware back button or through the browser the entire current state will be popped, i.e. the slider won’t go back to the previous image. Depending on your situation, this could be either a feature or a bug (it’s a feature in my case).