class MiniRouter {
router: SolidJSX.JSX.Element;
paths: Record<string, RouterComponent>;
currentPath: {set: (value: string) => void, get: Accessor<string>};
currentPathProps?: Record<string, any>;
history: {
past: { [p: string]: RouterComponent }[],
future: { [p: string]: RouterComponent }[],
push: (path: string) => void,
};
navigate: (path: string) => void;
forwards: () => void;
backwards: () => void;
constructor(props: MiniRouterProps) {
this.paths = props.paths;
this.paths["404"] = { element: props.invalid ?? (() => <div></div>)};
const [getCurrentPath, setCurrentPath] = createSignal<string>(props.currentPath ?? "404");
this.currentPath = {set: setCurrentPath, get: getCurrentPath};
const currentElement = createMemo(() => {
let x = (this.paths[this.currentPath.get()] ?? this.paths["404"]);
x.props = this.currentPathProps;
return x;
});
this.history = {
past: [],
future: [],
push: (path: string) => {
this.history.past.push({[this.currentPath.get()]: currentElement()});
this.currentPath.set(path);
}
}