Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing params with router.back()

I'm using expo-router and need to pass some params back. How to do that?

I use router push here:

<TouchableOpacity style={styles.qrButton} onPress={()=> {router.push(`/rent-bike/qr-scanner`)}}>
                    <Text style={styles.qrText}>Użyj kodu QR</Text>
                </TouchableOpacity>

Then I scan QR code and want to pass it back to display on same page:

    const handleBarCodeScanned = ({type, data}) => {
        setScanData(true)
        console.log(`data: ${data}`);
        console.log(`type: ${type}`);
        router.back()
    };

I can't see any solutions.

like image 604
rafauoo Avatar asked Mar 15 '26 22:03

rafauoo


2 Answers

Go back then update the route parameters.

router.back()
router.setParams({ foo: "bar" })
like image 121
Sam Tags Avatar answered Mar 17 '26 12:03

Sam Tags


How about using router.replace instead of goBack(). That way you can add params: router.replace({pathname: 'some-path', params: {param: qrData }}).

like image 33
Dugnad Avatar answered Mar 17 '26 12:03

Dugnad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!