File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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) {
2323 if ( ! route . matched [ 0 ] ) {
2424 return
2525 }
26-
26+ const hasAMPPrefix = route . path === '/amp' || route . path . indexOf ( '/amp/' ) === 0
2727 const { options } = route . matched [ 0 ] . components . default
28+ const metaAMP = Array . isArray ( route . meta ) ? route . meta [ 0 ] . amp : route . meta . amp
2829
2930 let ampMode = pick (
3031 options . amp ,
31- route . meta . amp ,
32+ metaAMP ,
3233 '<%= options.mode %>'
3334 )
3435
@@ -41,7 +42,7 @@ export default function (ctx, inject) {
4142 ampMode = 'only'
4243 break
4344 case 'hybrid' :
44- isAMP = route . path === '/amp' || route . path . indexOf ( '/amp/' ) === 0
45+ isAMP = hasAMPPrefix
4546 ampMode = 'hybrid'
4647 break
4748 case false :
@@ -62,6 +63,10 @@ export default function (ctx, inject) {
6263 inject ( 'isAMP' , isAMP )
6364 inject ( 'ampMode' , ampMode )
6465
66+ if ( ! isAMP && hasAMPPrefix ) {
67+ ctx . error ( { statusCode : 404 , message : 'This page could not be found' } )
68+ }
69+
6570 if ( ampMode !== false && ! options . _amp ) {
6671 options . head = createCustomHead ( options . head )
6772 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', () => {
146146 expect ( await isValid ( source ) ) . toEqual ( true )
147147 } )
148148} )
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