fix: ParentRoute view reuse

This commit is contained in:
luoxiao 2024-08-22 10:43:36 +08:00 committed by luoxiaozero
parent 482bfdb875
commit 51b04d911b
3 changed files with 66 additions and 60 deletions

View file

@ -21,6 +21,7 @@ send_wrapper = "0.6"
console_error_panic_hook = "0.1.7"
console_log = "1"
log = "0.4"
js-sys = "0.3.70"
[features]
default = ["csr"]

View file

@ -58,6 +58,7 @@ fn TheRouter() -> impl IntoView {
<Route path=path!("/development/components") view=DevelopmentComponentsMdPage/>
</ParentRoute>
<ParentRoute path=path!("/components") view=ComponentsPage>
{view!{
<Route path=path!("/accordion") view=AccordionMdPage/>
<Route path=path!("/anchor") view=AnchorMdPage/>
<Route path=path!("/auto-complete") view=AutoCompleteMdPage/>
@ -72,8 +73,8 @@ fn TheRouter() -> impl IntoView {
<Route path=path!("/color-picker") view=ColorPickerMdPage/>
<Route path=path!("/combobox") view=ComboboxMdPage/>
<Route path=path!("/config-provider") view=ConfigProviderMdPage/>
</ParentRoute>
<ParentRoute path=path!("/components") view=ComponentsPage>
}.into_inner()}
{view!{
<Route path=path!("/date-picker") view=DatePickerMdPage/>
<Route path=path!("/dialog") view=DialogMdPage/>
<Route path=path!("/divider") view=DividerMdPage/>
@ -90,8 +91,8 @@ fn TheRouter() -> impl IntoView {
<Route path=path!("/nav") view=NavMdPage/>
<Route path=path!("/pagination") view=PaginationMdPage/>
<Route path=path!("/popover") view=PopoverMdPage/>
</ParentRoute>
<ParentRoute path=path!("/components") view=ComponentsPage>
}.into_inner()}
{view!{
<Route path=path!("/progress-bar") view=ProgressBarMdPage/>
<Route path=path!("/radio") view=RadioMdPage/>
<Route path=path!("/scrollbar") view=ScrollbarMdPage/>
@ -108,10 +109,11 @@ fn TheRouter() -> impl IntoView {
<Route path=path!("/textarea") view=TextareaMdPage/>
<Route path=path!("/time-picker") view=TimePickerMdPage/>
<Route path=path!("/toast") view=ToastMdPage />
</ParentRoute>
<ParentRoute path=path!("/components") view=ComponentsPage>
}.into_inner()}
{view!{
<Route path=path!("/tooltip") view=TooltipMdPage />
<Route path=path!("/upload") view=UploadMdPage/>
}.into_inner()}
</ParentRoute>
</Routes>
</Router>

View file

@ -77,14 +77,17 @@ pub fn SiteHeader() -> impl IntoView {
#[cfg(any(feature = "csr", feature = "hydrate"))]
{
use leptos::ev;
let handle = window_event_listener(ev::keydown, move |event| {
let key = event.key();
let handle = window_event_listener(ev::keydown, move |e| {
if js_sys::Reflect::has(&e, &js_sys::wasm_bindgen::JsValue::from_str("key")).unwrap_or_default() {
let key = e.key();
if key == *"/" {
if let Some(auto_complete_ref) = auto_complete_ref.get_untracked() {
event.prevent_default();
e.prevent_default();
auto_complete_ref.focus();
}
}
}
});
on_cleanup(move || handle.remove());
}