diff --git a/examples/navigation/package.json b/examples/navigation/package.json index cfd0bb8..e9a06f1 100644 --- a/examples/navigation/package.json +++ b/examples/navigation/package.json @@ -10,7 +10,7 @@ }, "dependencies": { "@frui.ts/views": "^999.0.0", - "@tanstack/react-location": "^3.7.4", + "@tanstack/react-router": "^0.0.1-beta.82", "mobx": "6.7.0", "mobx-react-lite": "3", "react": "^18.2.0", diff --git a/examples/navigation/src/customers/customersViewModel.ts b/examples/navigation/src/customers/customersViewModel.ts index 4487273..5bbc24d 100644 --- a/examples/navigation/src/customers/customersViewModel.ts +++ b/examples/navigation/src/customers/customersViewModel.ts @@ -1,7 +1,9 @@ +import type { IViewModel, NavigationContext, NoParams } from "@frui.ts/views"; import { makeObservable, observable, runInAction } from "mobx"; -import type { IViewModel, SearchType } from "@frui.ts/views"; -export default class CustomersViewModel implements IViewModel { +type SearchScheme = { name?: string }; + +export default class CustomersViewModel implements IViewModel { @observable search?: string; @@ -9,9 +11,21 @@ export default class CustomersViewModel implements IViewModel { makeObservable(this); } - onNavigate(search: SearchType) { + onNavigate({ search }: NavigationContext) { + console.log("customers navigate", search); + runInAction(() => { - this.search = search.name as string; + this.search = search.name; }); } + + onDeactivate(context: NavigationContext) { + console.log("customers deactivate"); + } + + static validateSearch(search: Record) { + return { + name: search.name as string | undefined, + }; + } } diff --git a/examples/navigation/src/home/homeView.tsx b/examples/navigation/src/home/homeView.tsx index 5127fdb..20b4998 100644 --- a/examples/navigation/src/home/homeView.tsx +++ b/examples/navigation/src/home/homeView.tsx @@ -1,34 +1,51 @@ import { registerViewComponent } from "@frui.ts/views"; -import { Link, Outlet } from "@tanstack/react-location"; +import { Link, Outlet } from "@tanstack/react-router"; import { Observer } from "mobx-react-lite"; import React from "react"; import HomeViewModel from "./homeViewModel"; export const HomeView = registerViewComponent(HomeViewModel, vm => { + const linkProps = { + activeProps: { style: { color: "red" } }, + activeOptions: { + exact: true, + }, + }; + return (