Skip to content

Commit

Permalink
Update config based routing (#908)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
brenelz and kodiakhq[bot] authored Oct 3, 2024
1 parent 98f9fff commit 3dd5613
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/routes/solid-router/getting-started/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ Solid Router allows for configuration-based routing, where JSX is not needed to
To define a single route, a route definition object can be passed to the [`<Router>`](/solid-router/reference/components/router) component:

```jsx
import { lazy } from "solid-js";
import { render } from "solid-js/web";
import { Router } from "@solidjs/router";

const routes = {
path: "/",
component: import("/routes/index.js"),
component: lazy(() => import("/routes/index.js")),
}


Expand All @@ -24,21 +25,22 @@ In the route definition object, a `path` property must be provided to define the
To define multiple routes, an array of route definition objects can be passed to the `<Router>`] component:

```jsx
import { lazy } from "solid-js";
import { render } from "solid-js/web";
import { Router } from "@solidjs/router";

const routes = [
{
path: "/",
component: import("/routes/index.js"),
component: lazy(() => import("/routes/index.js")),
},
{
path: "/hello-world",
component: <h1>Hello, World!</h1>
component: () => <h1>Hello, World!</h1>
},
{
path: "/about",
component: import("/routes/about.js"),
component: lazy(() => import("/routes/about.js")),
}
]

Expand All @@ -50,7 +52,7 @@ Each path in the array of route definition objects will be matched against the c
In the example above, the root path (`/`) renders the `Home` page, the path `/hello-world` renders an `h1` element, and the path `/about` renders the `About` component.

<Callout title="Lazy Loading">
While not necessary, when using configuration-based routing, it is best practice to use the [`lazy`](/reference/component-apis/lazy) component to load components asynchronously.
When using configuration-based routing, it is best practice to use the [`lazy`](/reference/component-apis/lazy) component to load components asynchronously.
This will help improve the performance of your application by only loading the components when they are needed.

```jsx
Expand All @@ -65,7 +67,7 @@ const routes = [
},
{
path: "/hello-world",
component: <h1>Hello, World!</h1>
component: () => <h1>Hello, World!</h1>
},
{
path: "/about",
Expand Down

0 comments on commit 3dd5613

Please sign in to comment.