Solution to what I had seen as a bug.

This commit is contained in:
Eric van der Vlist 2022-11-25 15:55:03 +01:00
parent 1548e81f13
commit 63e5076211
1 changed files with 9 additions and 5 deletions

View File

@ -1,6 +1,6 @@
/* @refresh reload */ /* @refresh reload */
import { render } from 'solid-js/web'; import { render } from 'solid-js/web';
import type { Component } from 'solid-js'; import { Component, createEffect, createSignal, onMount } from 'solid-js';
import { import {
Router, Router,
@ -10,15 +10,19 @@ import {
useParams, useParams,
useNavigate, useNavigate,
hashIntegration, hashIntegration,
useRouteData,
} from '@solidjs/router'; } from '@solidjs/router';
const Counter: Component = () => { const Counter: Component = () => {
const params = useParams(); const params = useParams();
const count = +params.count; const [count, setCount] = createSignal(0);
createEffect(() => {
setCount(+params.count);
});
const navigate = useNavigate(); const navigate = useNavigate();
return ( return (
<> <>
<button onClick={() => navigate(`/counter/${count + 1}`)}>+1</button> <button onClick={() => navigate(`/counter/${count() + 1}`)}>+1</button>
<div>Count: {count}</div> <div>Count: {count}</div>
</> </>
); );
@ -32,10 +36,10 @@ const App: Component = () => {
</Routes> </Routes>
); );
}; };
// source={hashIntegration()}
render( render(
() => ( () => (
<Router source={hashIntegration()}> <Router >
<App /> <App />
</Router> </Router>
), ),