Skip to content

Commit

Permalink
docs(boring-stack): add routing page
Browse files Browse the repository at this point in the history
  • Loading branch information
DominusKelvin committed Jan 31, 2024
1 parent 4759187 commit 9323c54
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/boring-stack/routing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: Routing
titleTemplate: The Boring JavaScript Stack 🥱
description: In The Boring JavaScript Stack, all of your application's routes are defined server-side. This means that you don't need Vue Router or React Router.
prev:
text: 'Getting Started'
link: '/boring-stack/getting-started'
editLink: true
---

# Routing

## Defining routes

In The Boring JavaScript Stack, all of your application's routes are defined server-side. This means that you don't need Vue Router or React Router.

Instead, you can simply define [Sails routes](https://sailsjs.com/documentation/concepts/routes) and return an Inertia responses for SPA or return a server-side view for server-side rendering from those routes.

For example let's say we want to create a `/users` route, we can define the route in `config/routes.js`:

```js
module.exports.routes = {
'GET /users': 'user/view-users' // [!code focus]
}
```

The above route definition means that when a user requests the `/users` page of your app, the `view-users` action of the `user` controller will handle that request. Let's implement `user/view-users`.

::: tip
Run `npx sails generate action user/view-users` to scaffold the action.
:::

```js
module.exports = {
inputs: {},
exits: {
success: {}
},
fn: async function (inputs) {
const users = await User.find()
return sails.inertia.render('users/index', { users }) // [!code focus]
}
}
```

0 comments on commit 9323c54

Please sign in to comment.