Skip to content

Commit

Permalink
Exclude WASI on yew-router browser interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
langyo committed Dec 9, 2023
1 parent 34b64ca commit 44e1442
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
14 changes: 10 additions & 4 deletions packages/yew-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,20 @@ pub mod switch;
pub mod utils;

pub use routable::{AnyRoute, Routable};
pub use router::{BrowserRouter, HashRouter, Router};
pub use router::Router;
#[cfg(not(target_os = "wasi"))]
pub use router::{BrowserRouter, HashRouter};
pub use switch::Switch;

pub mod history {
//! A module that provides universal session history and location information.

pub use gloo::history::{
AnyHistory, BrowserHistory, HashHistory, History, HistoryError, HistoryResult, Location,
MemoryHistory,
AnyHistory, History, HistoryError, HistoryResult, Location, MemoryHistory,
};

#[cfg(not(target_os = "wasi"))]
pub use gloo::history::{BrowserHistory, HashHistory};
}

pub mod prelude {
Expand All @@ -102,5 +106,7 @@ pub mod prelude {
pub use crate::scope_ext::{LocationHandle, NavigatorHandle, RouterScopeExt};
#[doc(no_inline)]
pub use crate::Routable;
pub use crate::{BrowserRouter, HashRouter, Router, Switch};
#[cfg(not(target_os = "wasi"))]
pub use crate::{BrowserRouter, HashRouter};
pub use crate::{Router, Switch};
}
3 changes: 3 additions & 0 deletions packages/yew-router/src/navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub type NavigationResult<T> = HistoryResult<T>;
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum NavigatorKind {
/// Browser History.
#[cfg(not(target_os = "wasi"))]
Browser,
/// Hash History.
Hash,
Expand Down Expand Up @@ -150,7 +151,9 @@ impl Navigator {
/// Returns the Navigator kind.
pub fn kind(&self) -> NavigatorKind {
match &self.inner {
#[cfg(not(target_os = "wasi"))]
AnyHistory::Browser(_) => NavigatorKind::Browser,
#[cfg(not(target_os = "wasi"))]
AnyHistory::Hash(_) => NavigatorKind::Hash,
AnyHistory::Memory(_) => NavigatorKind::Memory,
}
Expand Down
11 changes: 9 additions & 2 deletions packages/yew-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ use std::rc::Rc;
use yew::prelude::*;
use yew::virtual_dom::AttrValue;

use crate::history::{AnyHistory, BrowserHistory, HashHistory, History, Location};
use crate::history::{AnyHistory, History, Location};
#[cfg(not(target_os = "wasi"))]
use crate::history::{BrowserHistory, HashHistory};
use crate::navigator::Navigator;
use crate::utils::{base_url, strip_slash_suffix};

#[cfg(not(target_os = "wasi"))]
use crate::utils::base_url;
use crate::utils::strip_slash_suffix;

/// Props for [`Router`].
#[derive(Properties, PartialEq, Clone)]
Expand Down Expand Up @@ -144,6 +149,7 @@ pub struct ConcreteRouterProps {
///
/// The router will by default use the value declared in `<base href="..." />` as its basename.
/// You may also specify a different basename with props.
#[cfg(not(target_os = "wasi"))]
#[function_component(BrowserRouter)]
pub fn browser_router(props: &ConcreteRouterProps) -> Html {
let ConcreteRouterProps { children, basename } = props.clone();
Expand All @@ -167,6 +173,7 @@ pub fn browser_router(props: &ConcreteRouterProps) -> Html {
/// # Warning
///
/// Prefer [`BrowserRouter`] whenever possible and use this as a last resort.
#[cfg(not(target_os = "wasi"))]
#[function_component(HashRouter)]
pub fn hash_router(props: &ConcreteRouterProps) -> Html {
let ConcreteRouterProps { children, basename } = props.clone();
Expand Down

0 comments on commit 44e1442

Please sign in to comment.