howljs / react-native-auto-route

React Native Auto Route is a file-based router for React Native CLI
https://howljs.github.io/react-native-auto-route/
MIT License
28 stars 2 forks source link

Query Parameter #2

Closed dbol667 closed 2 months ago

dbol667 commented 3 months ago

Thanks for a nice package!

Why not use plain old query parameter instead of struggling route parameter with strange file names etc?

router.navigate("product?id=22")

=> product.tsx

router.getParam("id")

howljs commented 2 months ago

This can still be done as usual. For example, if you want to go to the product screen with id 22 or any value.

For example, the structure of folders and files could be:

---home.tsx
---product.tsx
---post
------edit.tsx

home.tsx

const router = useRouter();

// Go to product
router.push('product?id=1&name=apple&price=100');

// Go to edit product
router.push('post/edit?id=1&example1=xxx&example2=xxx');

product.tsx

 const params = useParams();
 console.log(params); // {"id": "1", "name": "apple", "price": "100"}

post.tsx

 const params = useParams();
 console.log(params); // {"id": "1", "example1": "xxx", "example2": "xxx"}
howljs commented 2 months ago

There are quite a few ways to write it, as long as you understand the structure of creating directories, you will be able to do quite a lot