Closed devcaeg closed 3 months ago
Hey @devcaeg! This is because you're trying to navigate on the server, when the navigate
function is used for programmatic SPA navigation based on an interaction.
import { component$, useSignal, useTask$ } from '@builder.io/qwik';
import { isServer } from '@builder.io/qwik/build';
import { useNavigate, type DocumentHead } from '@builder.io/qwik-city';
export default component$(() => {
const navigate = useNavigate();
const isClickedSig = useSignal<boolean>(false);
useTask$(({ track }) => {
track(() => isClickedSig.value);
if (isServer) return;
navigate('/demo/flower');
});
return <button onClick$={() => (isClickedSig.value = true)}>Hello</button>;
});
export const head: DocumentHead = {
title: 'Welcome to Qwik',
meta: [
{
name: 'description',
content: 'Qwik site description',
},
],
};
This works, because we make sure not to run the navigate function on the server.
@thejackshelton
You're right, that was the problem, big mistake of mine haha.
Which component is affected?
Qwik Runtime
Describe the bug
Use
useNavigate
inuseTask$
generate an error:Reproduction
https://stackblitz.com/edit/qwik-starter-2jfbxe?file=src%2Froutes%2Findex.tsx
Steps to reproduce
No response
System Info
Additional Information
No response