how to make route's resources rerun on changing the page

GitHub
learn-anything/src/routes/[user]/[topic].tsx at main · learn-anythi...
Organize world's knowledge, explore connections and curate learning paths - learn-anything/src/routes/[user]/[topic].tsx at main · learn-anything/learn-anything
7 Replies
nikivi
nikiviOP2y ago
in the image above when i click on the sidebar items
nikivi
nikiviOP2y ago
it changes the url
nikivi
nikiviOP2y ago
nikivi
nikiviOP2y ago
but these resources don't rerun is it possible to rerun them? i thought if i change the page it would rerun the route but apparently it doesnt do it, i tested it with onMount http://localhost:3000/@nikita/zsh to http://localhost:3000/@nikita/physics for example
const res = await fetch(`http://127.0.0.1:3000/topic`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
topic: params.topic,
user: params.user.replace("@", ""),
}),
})
const res = await fetch(`http://127.0.0.1:3000/topic`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
topic: params.topic,
user: params.user.replace("@", ""),
}),
})
it should run this again with new params values
<a href={`/${params.user}/${topic.name}`}>
{topic.prettyName}
</a>
<a href={`/${params.user}/${topic.name}`}>
{topic.prettyName}
</a>
if i do this it works but i want A for client side transitions, i just need to trigger resource to rerun somehow
MAST
MAST2y ago
I think you can pass something to it to use it as a flat to make it rerun.
const [user] = createResource(id, fetchUser);
const [user] = createResource(id, fetchUser);
If id changes it reruns.
nikivi
nikiviOP2y ago
const [topic] = createResource(
() => params.topic,
async () => {
const [topic] = createResource(
() => params.topic,
async () => {
i have this now does that not mean that if topic changes it should rerun? where params is
const params = useParams()
const params = useParams()
MAST
MAST2y ago
It should rerun I think... I don't know what could be wrong.
Want results from more Discord servers?
Add your server