Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into fix/param-optionality
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jun 9, 2022
2 parents 74d69db + b31186b commit 7c8d2fc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
17 changes: 17 additions & 0 deletions docs/content/3.api/1.composables/use-request-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# `useRequestEvent`

Nuxt provides composables and utilities for first-class server-side-rendering support.

Within your pages, components, and plugins you can use `useRequestEvent` to access the incoming request.

```js
// Get underlying request event
const event = useRequestEvent()

// Get the URL
const url = event.req.url
```

::alert{icon=👉}
In the browser, `useRequestEvent` will return `undefined`.
::
2 changes: 1 addition & 1 deletion docs/content/migration/6.pages-and-layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ definePageMeta({
transition: {
name: 'page',
},
keepAlive: {
keepalive: {
exclude: ['modal']
},
})
Expand Down
4 changes: 4 additions & 0 deletions packages/nuxt/src/pages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ export function generateRoutesFromFiles (files: string[], pagesDir: string): Nux
}

parent.push(route)
// TODO: https://github.com/vuejs/router/issues/1435
parent.sort((a, b) => getSortablePath(a.path).localeCompare(getSortablePath(b.path)))
}

return prepareRoutes(routes)
}

const getSortablePath = (path: string) => path.replace(/^\//, '').replace(/:/, 'Z')

function getRoutePath (tokens: SegmentToken[]): string {
return tokens.reduce((path, token) => {
return (
Expand Down
44 changes: 25 additions & 19 deletions packages/nuxt/test/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,23 @@ describe('pages:generateRoutesFromFiles', () => {
children: []
},
{
name: 'slug',
path: '/:slug',
file: `${pagesDir}/[slug].vue`,
name: 'nonopt-slug',
path: '/nonopt/:slug',
file: `${pagesDir}/nonopt/[slug].vue`,
children: []
},
{
name: 'opt-slug',
path: '/opt/:slug?',
file: `${pagesDir}/opt/[[slug]].vue`,
children: []
},
{
children: [],
name: 'bar',
file: 'pages/[bar]/index.vue',
path: '/:bar'
},
{
children: [
{
Expand All @@ -132,21 +144,9 @@ describe('pages:generateRoutesFromFiles', () => {
path: '/:foo?'
},
{
children: [],
name: 'bar',
file: 'pages/[bar]/index.vue',
path: '/:bar'
},
{
name: 'nonopt-slug',
path: '/nonopt/:slug',
file: `${pagesDir}/nonopt/[slug].vue`,
children: []
},
{
name: 'opt-slug',
path: '/opt/:slug?',
file: `${pagesDir}/opt/[[slug]].vue`,
name: 'slug',
path: '/:slug',
file: `${pagesDir}/[slug].vue`,
children: []
},
{
Expand All @@ -159,8 +159,14 @@ describe('pages:generateRoutesFromFiles', () => {
},
{
description: 'should generate correct catch-all route',
files: [`${pagesDir}/[...slug].vue`],
files: [`${pagesDir}/[...slug].vue`, `${pagesDir}/index.vue`],
output: [
{
name: 'index',
path: '/',
file: `${pagesDir}/index.vue`,
children: []
},
{
name: 'slug',
path: '/:slug(.*)*',
Expand Down

0 comments on commit 7c8d2fc

Please sign in to comment.