Skip to content

Commit

Permalink
fix(app): SPA on GitHub Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Nov 1, 2023
1 parent 82c1dbc commit c8c20fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
var l = window.location;
l.replace(
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?r=/' +
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
l.hash
Expand Down
17 changes: 15 additions & 2 deletions app/src/pages/home.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
use leptos::*;
use leptos_i18n::Locale;
use leptos_router::A;
use leptos_router::{use_navigate, use_query_map, NavigateOptions, A};

use crate::{i18n::*, GlobalState};

#[component]
pub fn Home() -> impl IntoView {
let GlobalState { version, .. } = expect_context();
let navigate = use_navigate();
let query = use_query_map();
let i18n = use_i18n();

create_effect(move |_| {
let query = query.get();
if let Some(r) = query.get("r") {
log::debug!("r: {:?}", r);
navigate(r, NavigateOptions::default());
}
});

view! {
<section class="w-full hero text-center p-5 sm:py-19">
<h1 class="text-8 sm:text-10 font-medium">{t!(i18n, description)}</h1>
<p class="text-4 sm:text-5 mt-4.5 mb-7.5 sm:mt-6 sm:mb-8 op-61.8 font-light" inner_html={t!(i18n, builts_on)}></p>
<A href=move || format!("/{}/{}/guide/introduction", i18n.get_locale().as_str(), version.get()) class="inline-block bg-neutral-900 text-neutral-100 dark:bg-neutral-100 dark:text-neutral-900 shadow py-2 px-4.5 border-rounded font-medium text-4 cursor-pointer">{t!(i18n, get_started)}</A>
<A
class="inline-block bg-neutral-900 text-neutral-100 dark:bg-neutral-100 dark:text-neutral-900 shadow py-2 px-4.5 border-rounded font-medium text-4 cursor-pointer"
href=move || format!("/{}/{}/guide/introduction", i18n.get_locale().as_str(), version.get())
>{t!(i18n, get_started)}</A>
</section>
}
}

0 comments on commit c8c20fb

Please sign in to comment.