Skip to main content
Frontend tutorial

5.3. Add view to URL params

Choose Loadings and reload the page: you're back on the dashboard. The selected loading doesn't have this problem. Open a row, reload, and the dialog is still there, because UI.init reads loading from the URL and a reaction writes it back. Let's do the same for the view:

src/store/UI.ts
init = () => {
const urlSearchParams = new URLSearchParams(window.location.search);

const view = urlSearchParams.get("view");
if (view === "loadings") {
this.view = "loadings";
}

const loadingId = urlSearchParams.get("loading");
// ...

reaction(() => this.view,
view => addQueryParam("view", view, "dashboard"));
reaction(() => this.selectedLoading, loading => addQueryParam("loading", loading?.id ?? "", ""));
};

When the app starts, we only check for loadings. Anything else means the dashboard, our default. A reaction runs its second function every time the value returned by the first one changes. addQueryParam is already in the file. It puts the value into the URL, or removes it when it equals the default, so the dashboard needs no parameter at all.

Now you can send someone a link straight to the table: http://localhost:5173/?view=loadings.

05 / ShippingBoard Lite

localhost:5173/?view=loadings
The address localhost:5173/?view=loadings opens the loadings table with the Loadings button active.

A link with view=loadings opens the table.