mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 09:25:54 +00:00
feat(pages): add catchall support ([...id].vue
) (#254)
This commit is contained in:
parent
01b2c2c972
commit
1518a2a070
5
examples/pages/pages/catchall/[...id].vue
Normal file
5
examples/pages/pages/catchall/[...id].vue
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
test-{{ $route.params.id }}
|
||||||
|
</div>
|
||||||
|
</template>
|
@ -13,11 +13,13 @@ enum SegmentParserState {
|
|||||||
initial,
|
initial,
|
||||||
static,
|
static,
|
||||||
dynamic,
|
dynamic,
|
||||||
|
catchall,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SegmentTokenType {
|
enum SegmentTokenType {
|
||||||
static,
|
static,
|
||||||
dynamic,
|
dynamic,
|
||||||
|
catchall,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SegmentToken {
|
interface SegmentToken {
|
||||||
@ -93,15 +95,17 @@ function getRoutePath (tokens: SegmentToken[]): string {
|
|||||||
path +
|
path +
|
||||||
(token.type === SegmentTokenType.dynamic
|
(token.type === SegmentTokenType.dynamic
|
||||||
? `:${token.value}`
|
? `:${token.value}`
|
||||||
: encodePath(token.value))
|
: token.type === SegmentTokenType.catchall
|
||||||
|
? `:${token.value}(.*)*`
|
||||||
|
: encodePath(token.value))
|
||||||
)
|
)
|
||||||
}, '/')
|
}, '/')
|
||||||
}
|
}
|
||||||
|
|
||||||
const PARAM_CHAR_RE = /[\w\d_]/
|
const PARAM_CHAR_RE = /[\w\d_.]/
|
||||||
|
|
||||||
function parseSegment (segment: string) {
|
function parseSegment (segment: string) {
|
||||||
let state = SegmentParserState.initial
|
let state: SegmentParserState = SegmentParserState.initial
|
||||||
let i = 0
|
let i = 0
|
||||||
|
|
||||||
let buffer = ''
|
let buffer = ''
|
||||||
@ -119,7 +123,9 @@ function parseSegment (segment: string) {
|
|||||||
type:
|
type:
|
||||||
state === SegmentParserState.static
|
state === SegmentParserState.static
|
||||||
? SegmentTokenType.static
|
? SegmentTokenType.static
|
||||||
: SegmentTokenType.dynamic,
|
: state === SegmentParserState.dynamic
|
||||||
|
? SegmentTokenType.dynamic
|
||||||
|
: SegmentTokenType.catchall,
|
||||||
value: buffer
|
value: buffer
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -149,7 +155,12 @@ function parseSegment (segment: string) {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
|
case SegmentParserState.catchall:
|
||||||
case SegmentParserState.dynamic:
|
case SegmentParserState.dynamic:
|
||||||
|
if (buffer === '...') {
|
||||||
|
buffer = ''
|
||||||
|
state = SegmentParserState.catchall
|
||||||
|
}
|
||||||
if (c === ']') {
|
if (c === ']') {
|
||||||
consumeBuffer()
|
consumeBuffer()
|
||||||
state = SegmentParserState.initial
|
state = SegmentParserState.initial
|
||||||
|
Loading…
Reference in New Issue
Block a user