link clicking
This commit is contained in:
parent
64a4a82ac8
commit
ca556e3a68
@ -10,7 +10,8 @@ export default ()=>
|
|||||||
return <div class="p-4 text-red-500">
|
return <div class="p-4 text-red-500">
|
||||||
<Iso.Metas title="Component!"/>
|
<Iso.Metas title="Component!"/>
|
||||||
Route is: {routeGet.Path.toString()}
|
Route is: {routeGet.Path.toString()}
|
||||||
<button className="p-4 bg-red-500 text-white" onClick={e=>{countSet(countGet+1); routeSet(["lol", "idk"], {count:countGet});}}>{countGet}</button>
|
<button className="p-4 bg-red-500 text-white" onClick={e=>{countSet(countGet+1); routeSet(["lol", "idk"], {count:countGet+1});}}>{countGet}</button>
|
||||||
Component!!!
|
Component!!!
|
||||||
|
<a href="/custom/page" className="p-2 text(lg blue-500) font-bold">a link</a>
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
32
lib/iso.tsx
32
lib/iso.tsx
@ -22,9 +22,6 @@ export const Metas =(props:{concatListed?:boolean; dropUnlisted?:boolean}&MetasI
|
|||||||
const propValue = props[metaKey]||"";
|
const propValue = props[metaKey]||"";
|
||||||
propValue ? additive(metaKey, propValue) : subtractive(metaKey);
|
propValue ? additive(metaKey, propValue) : subtractive(metaKey);
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(`rendering metas`, Meta)
|
|
||||||
|
|
||||||
if(window.innerWidth)
|
if(window.innerWidth)
|
||||||
{
|
{
|
||||||
document.title = Meta.title;
|
document.title = Meta.title;
|
||||||
@ -51,7 +48,7 @@ export const Router = {
|
|||||||
Provider(props:RouteProps)
|
Provider(props:RouteProps)
|
||||||
{
|
{
|
||||||
const [routeGet, routeSet] = React.useState(Router.Parse(props.url || new URL(document.location.href)));
|
const [routeGet, routeSet] = React.useState(Router.Parse(props.url || new URL(document.location.href)));
|
||||||
const [dirtyGet, dirtySet] = React.useState(false);
|
const [dirtyGet, dirtySet] = React.useState(true);
|
||||||
|
|
||||||
const routeUpdate:RouteContext[1] =(inPath, inParams, inAnchor)=>
|
const routeUpdate:RouteContext[1] =(inPath, inParams, inAnchor)=>
|
||||||
{
|
{
|
||||||
@ -64,17 +61,32 @@ export const Router = {
|
|||||||
Params: inParams || routeGet.Params,
|
Params: inParams || routeGet.Params,
|
||||||
Anchor: inAnchor || routeGet.Anchor
|
Anchor: inAnchor || routeGet.Anchor
|
||||||
});
|
});
|
||||||
dirtySet(true);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// when the state changes, update the page url
|
// when the state changes, update the page url
|
||||||
React.useEffect(()=>{
|
React.useEffect(()=> dirtyGet ? dirtySet(false) : history.pushState({...routeGet, URL:undefined}, "", routeGet.URL), [routeGet.URL.href]);
|
||||||
history.pushState({...routeGet, URL:undefined}, "", routeGet.URL);
|
|
||||||
}, [routeGet.URL.href]);
|
|
||||||
|
|
||||||
React.useEffect(()=>{
|
React.useEffect(()=>{
|
||||||
// when the history changes, update the state
|
history.replaceState({...routeGet, URL:undefined}, "", routeGet.URL);
|
||||||
window.addEventListener("popstate", ({state})=>{routeUpdate(state.Path, state.Params, state.Anchor)});
|
window.addEventListener("popstate", ({state})=>
|
||||||
|
{
|
||||||
|
dirtySet(true);
|
||||||
|
routeUpdate(state.Path, state.Params, state.Anchor);
|
||||||
|
});
|
||||||
|
document.addEventListener("click", e=>
|
||||||
|
{
|
||||||
|
const t = e.target as HTMLAnchorElement;
|
||||||
|
if(t.href)
|
||||||
|
{
|
||||||
|
const u = new URL(t.href);
|
||||||
|
if(u.origin == document.location.origin)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
const parts = Router.Parse(u);
|
||||||
|
routeUpdate(parts.Path, parts.Params, parts.Anchor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return <Router.Context.Provider value={[routeGet, routeUpdate]}>
|
return <Router.Context.Provider value={[routeGet, routeUpdate]}>
|
||||||
|
@ -35,7 +35,7 @@ const Transpileable =(inFilePath:string):boolean=>
|
|||||||
};
|
};
|
||||||
const Transpile =async(inCode:string, inKey:string):Promise<string>=>
|
const Transpile =async(inCode:string, inKey:string):Promise<string>=>
|
||||||
{
|
{
|
||||||
const transpile = await ESBuild.transform(inCode, { loader: "tsx", sourcemap: "inline", minify:true });
|
const transpile = await ESBuild.transform(inCode, { loader: "tsx", sourcemap: "inline", minify:false });
|
||||||
Transpiled.set(inKey, transpile.code);
|
Transpiled.set(inKey, transpile.code);
|
||||||
return transpile.code;
|
return transpile.code;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user