Quand je fais Router.Push
Ma page Rechargez, je m'attendrais à ce que la poussette soit utilisée.
Utilisation du code suivant dans le composant:
import Router from "next/router";
//other code
const search = useCallback(
e => {
e.preventDefault();
Router.Push(
`/products-search/${encodeURIComponent(
searchText
)}`,
`/products-search?q=${encodeURIComponent(
searchText
)}`
);
},
[searchText]
);
//other code
<form onSubmit={search}>
<input
type="text"
onChange={change}
value={searchText}
pattern=".{3,}"
title="3 characters minimum"
required
/>
<button type="submit">OK</button>
</form>
Ma page/produits-Search.js
ProductsSearch.getInitialProps = ({ query, store }) => {
//added try catch as next js may reload if there is an error
// running this on the client side
try {
const queryWithPage = withPage(query);
return {
query: queryWithPage
};
} catch (e) {
debugger;
}
};
Quand je passe un objet à Router.Push
cela fonctionne comme prévu:
const search = useCallback(
e => {
e.preventDefault();
Router.Push({
pathname: "/products-search",
query: { q: searchText }
});
},
[searchText]
);
Au cas où une âme perdue vient ici avec mon problème, c'était un peu invisible.
router.Push(
'/organizations/[oid]/clients/[uid]',
`/organizations/${oid}/clients/${id}`
);
est ce que j'ai écrit et il navigue sans rafraîchissement.
router.Push(
'/organizations/[oid]/clients/[cid]',// cid mistaken name but still worked. Should be uid
`/organizations/${oid}/clients/${id}`
);
Le nom de l'identification erroné a entraîné l'actualisation, bien qu'elle soit toujours navigue dans la bonne page. Alors, assurez-vous que les noms d'identification sont corrects.