File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div >
3
+ No to AMP
4
+ </div >
5
+ </template >
6
+
7
+ <script >
8
+ export default {
9
+ amp: false
10
+ }
11
+ </script >
Original file line number Diff line number Diff line change @@ -23,12 +23,13 @@ export default function (ctx, inject) {
23
23
if ( ! route . matched [ 0 ] ) {
24
24
return
25
25
}
26
-
26
+ const hasAMPPrefix = route . path === '/amp' || route . path . indexOf ( '/amp/' ) === 0
27
27
const { options } = route . matched [ 0 ] . components . default
28
+ const metaAMP = Array . isArray ( route . meta ) ? route . meta [ 0 ] . amp : route . meta . amp
28
29
29
30
let ampMode = pick (
30
31
options . amp ,
31
- route . meta . amp ,
32
+ metaAMP ,
32
33
'<%= options.mode %>'
33
34
)
34
35
@@ -41,7 +42,7 @@ export default function (ctx, inject) {
41
42
ampMode = 'only'
42
43
break
43
44
case 'hybrid' :
44
- isAMP = route . path === '/amp' || route . path . indexOf ( '/amp/' ) === 0
45
+ isAMP = hasAMPPrefix
45
46
ampMode = 'hybrid'
46
47
break
47
48
case false :
@@ -62,6 +63,10 @@ export default function (ctx, inject) {
62
63
inject ( 'isAMP' , isAMP )
63
64
inject ( 'ampMode' , ampMode )
64
65
66
+ if ( ! isAMP && hasAMPPrefix ) {
67
+ ctx . error ( { statusCode : 404 , message : 'This page could not be found' } )
68
+ }
69
+
65
70
if ( ampMode !== false && ! options . _amp ) {
66
71
options . head = createCustomHead ( options . head )
67
72
options . layout = createCustomLayout ( options . layout , options . ampLayout )
Original file line number Diff line number Diff line change @@ -146,3 +146,13 @@ describe('Render AMP Story', () => {
146
146
expect ( await isValid ( source ) ) . toEqual ( true )
147
147
} )
148
148
} )
149
+
150
+ describe ( 'Render disabled amp page' , ( ) => {
151
+ beforeAll ( async ( ) => {
152
+ await page . goto ( url ( '/amp/noamp' ) )
153
+ } )
154
+
155
+ test ( '404 for not amp pages' , async ( ) => {
156
+ await expect ( page ) . toMatch ( 'This page could not be found' )
157
+ } )
158
+ } )
You can’t perform that action at this time.
0 commit comments