0.1.30 β’ Published 3 years ago
solid-router-stack v0.1.30
ππ½ solid-router-stack
A solid router, mobile first.
Features:
- Like navigation, page is keep in dom
- Auto lazy load pages
- Easy preload some pages when entry a page
- Auto use URL params input page's props
- Tiny, only 3kbin gzip
Example
Create routers
import { render } from "solid-js/web";
import { createRouters, stackOptions } from "solid-router-stack";
import Welcome from "./welcome";
export const routers = createRouters({
  Welcome: {
    render: Welcome,
    // not use lazy import
    sync: true,
  },
  Login: {
    render: () => import("./sign/Login"),
    // preload other pages
    preload: ["User"],
  },
  User: {
    render: () => import("./user"),
  },
});
// Set page background:
stackOptions.className = "bg-gray-800";
render(
  () => <routers.Routers root={routers.Welcome} hash />,
  document.getElementById("root");
);Use Navigaion
import { routers } from "./routers";
function Welcome() {
  const handlePushProduct = () => {
    routers.user.push();
  };
  const handleReleaseProduct = () => {
    routers.user.replace({ id: "123" });
  };
  const handleClearToProduct = () => {
    routers.user.clearTo();
  };
  const handleGoBack = () => {
    routers.goBack();
  };
  return (
    <div>
      <div onclick={handlePushProduct}>push product</div>
      <div onclick={handleReleaseProduct}>release product</div>
      <div onclick={handleClearToProduct}>clear all stack and push product</div>
      <div onclick={handleGoBack}>go back</div>
    </div>
  );
}
export default Welcome;Use params
When sub page back, you can do something:
import { createPropsSignal } from "solid-router-stack";
// params.dog in props
function App(props: { dog: string; age: number }) {
  const [dog, setDog] = createPropsSignal(props, "dog");
  return (
    <div>
      <input oninput={(e) => setDog(e.currentTarget.value)} />
      <div>change and load: {dog()}</div>
      <div>only load: {p.age}</div>
    </div>
  );
}Not keep page
props.stackShow is when stack page is stack top, you can use <Show when={props.stackShow} /> change Not keep page:
const Page: Component = (props) => {
  return (
    <Show when={props.stackShow}>
      <div>the page</div>
    </Show>
  );
};Like desktop router push
routers.xxxx.put is push a new page or move old page to top
routers.user.put(); // push a new page or move old page to top
routers.user.put({}, true); // ignore animationAnimation navigation, like application
import { setNavigationAnimation } from "solid-router-stack";
// like application
setNavigationAnimation("moveTop");ignoreAnimation in once:
// routers.xxx.push(params?:Record<string, unknown>, ignoreAnimation?:boolean)
routers.user.push({}, true);
// routers.goBack(params?:Record<string, unknown>, ignoreAnimation?:boolean)
routers.goBack({}, true);Events listen
When use history change:
import { historyProxy } from "solid-router-stack";
historyProxy.beforeChange((url, path) => {
  if (path === "/user") {
    return "/login";
  }
  return url;
});Use virtual history
Use virtual history in iOS Wechat application, history stack only one.
export function isIOSWechat(): boolean {
  const ua = navigator.userAgent.toLocaleLowerCase();
  return  new RegExp("(iphone|ipod|ipad)").test(ua) && new RegExp("(micromessenger)").test(ua);
}
render(
  () => <routers.Routers root={routers.Welcome} hash virtualHistory={isIOSWechat()} />,
  document.getElementById("root");
);0.1.30
3 years ago
0.1.27
3 years ago
0.1.28
3 years ago
0.1.29
3 years ago
0.1.23
3 years ago
0.1.24
3 years ago
0.1.25
3 years ago
0.1.26
3 years ago
0.1.10
3 years ago
0.1.11
3 years ago
0.1.12
3 years ago
0.1.13
3 years ago
0.1.14
3 years ago
0.1.15
3 years ago
0.1.20
3 years ago
0.1.21
3 years ago
0.1.22
3 years ago
0.1.0
3 years ago
0.1.2
3 years ago
0.1.1
3 years ago
0.0.2
3 years ago
0.1.16
3 years ago
0.1.8
3 years ago
0.1.17
3 years ago
0.1.7
3 years ago
0.1.18
3 years ago
0.1.19
3 years ago
0.1.9
3 years ago
0.1.4
3 years ago
0.1.6
3 years ago
0.0.1
3 years ago