An open API service indexing awesome lists of open source software.

https://github.com/supertigerdev/solid-named-router

A named based router for solidjs
https://github.com/supertigerdev/solid-named-router

navigation router solidjs vue

Last synced: about 1 year ago
JSON representation

A named based router for solidjs

Awesome Lists containing this project

README

          


solid-named-router

# Solid Named Router

[![pnpm](https://img.shields.io/badge/maintained%20with-pnpm-cc00ff.svg?style=for-the-badge&logo=pnpm)](https://pnpm.io/)

A third party router library for solidjs. Includes named routes inspired by vuejs.
This router relies on the [route-parser](https://github.com/Unnamed-Chat-App/route-parser) package.
Note: This library is not complete. Please contribute and submit PRs to improve this library 💖

## Quick start

Install it:

```bash
npm i solid-named-router
```

Wrap your root component with the Router component:

```tsx
import { render } from "solid-js/web";
import { createRouter } from "solid-named-router";
import App from "./App";

const Router = createRouter({
routes: [
{
name: 'Home',
path: '/',
element: () =>

Home

},
{
name: 'Users',
path: '/users/:userId',
element: () =>
Users

},
]
});

render(
() => (



),
document.getElementById("app")
);
```

Now add the `RouterView` component to display the current route.
```tsx
import {RouterView, Link} from "solid-named-router";

const App = () => {
return (
<>

>
);
};
```

## Methods & Hooks
### Link
```tsx
User
User
```
### navigate
```ts
navigate({name: 'Users', params: {userId: 1234}, query: {hideInfo: "1"}})
navigate('app/users/1234')
```

### useNamedRoute
```ts
const namedRoute = useNamedRoute(); // -> {name, params, pathname, query};


name: {namedRoute.name}

params: {namedRoute.params.userId}

params: {namedRoute.pathname}


```
### useParams
```ts
const params = useParams(); // -> {userId};


name: {params.userId}


```

### Outlet Example
```tsx

const Router = createRouter({
routes: [
{
name: 'Users',
path: '/users/:userId',
elements: {
drawer: () =>

Drawer Here
,
content: () =>
Content Here

},
element: () => (




),
},
]
});
```