Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paring-chan/koa-inertia
Inertia.js protocol support for koa.js
https://github.com/paring-chan/koa-inertia
Last synced: 2 days ago
JSON representation
Inertia.js protocol support for koa.js
- Host: GitHub
- URL: https://github.com/paring-chan/koa-inertia
- Owner: paring-chan
- Created: 2021-09-19T13:30:09.000Z (over 3 years ago)
- Default Branch: dev
- Last Pushed: 2023-12-15T05:14:17.000Z (about 1 year ago)
- Last Synced: 2024-12-31T07:45:52.791Z (3 days ago)
- Language: TypeScript
- Size: 70.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Koa-Inertia
Unofficial server-side adapter for [inertia.js](https://inertiajs.com)
## Install
```shell
yarn add @pikokr/koa-inertia
```## Usage(Typescript)
views/app.pug
```pug
doctype htmlhtml(lang='ko')
head
title MyApp
script(type='text/javascript' src='/dist/js/app.js')
body
#root(data-page=pageData)
```### Render
```ts
import {inertia} from '@pikokr/koa-inertia'
import views from "koa-views";// ...
app.use(
views(__dirname + '/views', {
extension: 'pug',
}),
)app.use(inertia('app', '1' /* asset version */))
const router = new Router()
// ...
router.get('/', async ctx => {
await ctx.inertia.render('Index', {test: 1234})
})
```### Shared data
```ts
app.use((ctx, next) => {
ctx.inertia.share('share', 12345)
return next()
})
```### Redirect
```ts
ctx.inertia.location('https://google.com')
```