1

Im about to setup a product Page with ionic-react and @ionic-react-router. The products have different variants, soo I created a optional url parameter to enable smooth sharing.

My route is defined like this:

product: {
    component: ProductPage,
    background: '/images/dashboard-navigation-productOverview.png',
    key: 'PRODUCT',
    path: '/product/:id/:variantId?'
},

My ProductPage Component looks like this:

import React, { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import { IonPage, IonContent } from '@ionic/react';
....

const ProductPage = ({match}) => {
    const [variants, setVariants] = useState([]);
    const [source, setSource] = useState(null);
    const [variant, setVariant] = useState(null);

    useEffect(() => {
        (async () => {
            const response = await productService.getProduct(parseInt(match.params.id, 10))
            setSource(response);
        })();
    }, [match.params.id]);

    useEffect(() => {
        const variants = productHelpers.allVariantsFromSource(source);

        if (match.params.variantId) {
            const variant = productHelpers.getProductVariationById(variants, parseInt(match.params.variantId, 10));
            setVariant(variant || variants[0]);
        } else {
            // 0 is always main detail
            setVariant(variants[0]);
        }

        setVariants(variants);
    }, [source, match.params.variantId]);

    return <IonPage>
        <Toolbar title={(source) ? source.name : ''}/>
        <IonContent>
            <Product source={source} variant={variant} variants={variants}/>
        </IonContent>
    </IonPage>
}

export default ProductPage;

And somewhere in product I want to change the variation with replacing the url. So the user can use the back button, to get back where he comes from (mostly product list).

import React, {useContext} from "react";
import {IonButton, NavContext} from '@ionic/react';

const ProductVariant = ({source, newVariant}) => {
    const {navigate} = useContext(NavContext);


    return (
        <IonButton
           onClick={() => navigate(`/product/${source.id}/${newVariant.id}`, 'none', 'replace')}>{newVariant.name}</IonButton>

    );
};

My Problem

The page URL is updating like I want to, The back function is working too. But the page transition is still happening.

What i'm doing wrong??

Sysix
  • 1,572
  • 1
  • 16
  • 23

1 Answers1

1

I’m not a react developer, but I know an angular when we import ionic we have to set animation equal to false where we import the ionic module

Judson Terrell
  • 4,204
  • 2
  • 29
  • 45