Back to Wails

Routing

website/versioned_docs/version-v2.12.0/guides/routing.mdx

2.12.01.5 KB
Original Source

Routing

Routing is a popular way to switch views in an application. This page offers some guidance around how to do that.

Vue

The recommended approach for routing in Vue is Hash Mode:

js
import { createRouter, createWebHashHistory } from "vue-router";

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    //...
  ],
});

Angular

The recommended approach for routing in Angular is HashLocationStrategy:

ts
RouterModule.forRoot(routes, { useHash: true });

React

The recommended approach for routing in React is HashRouter:

jsx
import { HashRouter, Routes, Route } from "react-router-dom";

ReactDOM.render(
  <HashRouter basename={"/"}>
    <Routes>
      <Route path="/" element={<Page0 />} exact />
      <Route path="/page1" element={<Page1 />} />
      <Route path="/page2" element={<Page2 />} />
    </Routes>
  </HashRouter>,
  root
);

Svelte

The recommended approach for routing in Svelte is svelte-spa-router:

svelte
<script>
    import Router from "svelte-spa-router";
</script>

<Router
    routes={{
        "/": Home,
        "/products": wrap({
            asyncComponent: () => import("./routes/Products.svelte"),
        }),
        "/settings": Settings,
        "*": NotFound,
    }}
/>