Skip to content

Commit

Permalink
feat: routerMode, fix #143
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Jun 20, 2022
1 parent 3e4466e commit 1e337e3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
14 changes: 14 additions & 0 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ export default defineConfig({
})
```

## `routerMode`

`'history' | 'hash'` - Default: `'history'`

Changes the router mode:
- `'history'`: HTML 5 history mode with cleaner URLs.
- `'hash'`: Use the hashtag hack in the URL to support more servers and static hosting services.

```ts
export default defineConfig({
routerMode: 'hash',
})
```

## `vite`

`ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>)`
Expand Down
14 changes: 12 additions & 2 deletions packages/histoire/src/client/app/router.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { createRouter, createWebHistory } from 'vue-router'
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import { histoireConfig } from './util/config'

export const base = import.meta.env.BASE_URL as string

function createRouterHistory () {
switch (histoireConfig.routerMode) {
case 'hash': return createWebHashHistory(base)
case 'history':
default:
return createWebHistory(base)
}
}

export const router = createRouter({
history: createWebHistory(base),
history: createRouterHistory(),
routes: [
{
path: '/',
Expand Down
7 changes: 7 additions & 0 deletions packages/histoire/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ export interface HistoireConfig {
* Customize the markdown-it renderer
*/
markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>
/**
* Change the router mode.
* - history: use HTML history with cleaner URLs
* - hash: use hashtag hack in the URL to support more hosting services
*/
routerMode?: 'history' | 'hash'
/**
* Vite config override
*/
Expand Down Expand Up @@ -264,6 +270,7 @@ export function getDefaultConfig (): HistoireConfig {
},
],
sandboxDarkClass: 'dark',
routerMode: 'history',
}
}

Expand Down

0 comments on commit 1e337e3

Please sign in to comment.