fixed redirects

This commit is contained in:
MCorange 2023-09-30 22:57:54 +03:00
parent 3b1a278665
commit 062a893460
No known key found for this signature in database
GPG Key ID: BFC3CC200C408BD7
2 changed files with 20 additions and 22 deletions

View File

@ -7,12 +7,8 @@ import Blog from './components/Blog';
import Socials from './components/Socials'; import Socials from './components/Socials';
import About from './components/About'; import About from './components/About';
import Donate from "./components/Donate" import Donate from "./components/Donate"
import Redirect from './components/Redirect';
const redirects = [
{href: "/github", url: "https://github.com/MCorange99"},
{href: "/ko-fi", url: "https://ko-fi.com/mcorange"},
{href: "/mastadon", url: "https://river.group.lt/@mcorange"}
]
const App: Component = () => { const App: Component = () => {
return ( return (
@ -26,15 +22,15 @@ const App: Component = () => {
<Route path="/social" component={Socials} /> <Route path="/social" component={Socials} />
<Route path="/about" component={About} /> <Route path="/about" component={About} />
<Route path="/donate" component={Donate} /> <Route path="/donate" component={Donate} />
<Route path="/r"> <Route path="/r/:id" component={Redirect}>
{redirects.map((val)=>{ {/* {redirects.map((val)=>{
return ( return (
<Route path={val.href} component={()=>{ <Route path={val.href} component={()=>{
window.location.assign(val.url); window.location.assign(val.url);
return (<></>); return (<></>);
}}/> }}/>
) )
})} })} */}
</Route> </Route>
</Routes> </Routes>
</div> </div>

View File

@ -1,20 +1,22 @@
import { Route, Router, Routes } from "@solidjs/router"; import { Route, Router, Routes, useParams } from "@solidjs/router";
const redirects = {
"github": "https://github.com/MCorange99",
"ko-fi": "https://ko-fi.com/mcorange",
"mastadon": "https://river.group.lt/@mcorange",
};
export default () => { export default () => {
const p = window.location.pathname; const params = useParams();
console.log(p); //@ts-ignore
if (p.startsWith("/r")) { const url = (redirects[params["id"] as string] || "/") as string;
switch (p) { redirect(url);
case "/r/github":
redirect("https://github.com/MCorange99");
break
}
}
return ( return (
<> <h1>Redirecting...</h1>
</> )
);
} }