File tree 5 files changed +58
-4
lines changed
e2e-tests/development-runtime
cypress/integration/navigation 5 files changed +58
-4
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,21 @@ const runTests = () => {
40
40
)
41
41
} )
42
42
} )
43
+
44
+ it ( `should redirect to a dynamically-created replacement page` , ( ) => {
45
+ cy . visit ( `/redirect-me/` ) . waitForRouteChange ( )
46
+
47
+ cy . location ( `pathname` ) . should ( `equal` , `/pt/redirect-me/` )
48
+ cy . then ( ( ) => {
49
+ expect ( spy ) . not . to . be . calledWith (
50
+ `The route "/redirect" matches both a page and a redirect; this is probably not intentional.`
51
+ )
52
+
53
+ cy . findByText ( "This should be at /pt/redirect-me/" , {
54
+ exact : false ,
55
+ } ) . should ( `exist` )
56
+ } )
57
+ } )
43
58
}
44
59
45
60
describe ( `redirect` , ( ) => {
Original file line number Diff line number Diff line change @@ -104,10 +104,34 @@ exports.createPages = async function createPages({
104
104
}
105
105
106
106
exports . onCreatePage = async ( { page, actions } ) => {
107
- const { createPage } = actions
107
+ const { createPage, createRedirect , deletePage } = actions
108
108
109
109
if ( page . path . match ( / ^ \/ c l i e n t - o n l y - p a t h s / ) ) {
110
110
page . matchPath = `/client-only-paths/*`
111
111
createPage ( page )
112
112
}
113
+
114
+ if ( page . path === `/redirect-me/` ) {
115
+ const toPath = `/pt${ page . path } `
116
+
117
+ deletePage ( page )
118
+
119
+ createRedirect ( {
120
+ fromPath : page . path ,
121
+ toPath,
122
+ isPermanent : false ,
123
+ redirectInBrowser : true ,
124
+ Language : `pt` ,
125
+ statusCode : 301 ,
126
+ } )
127
+
128
+ createPage ( {
129
+ ...page ,
130
+ path : toPath ,
131
+ context : {
132
+ ...page . context ,
133
+ lang : `pt` ,
134
+ } ,
135
+ } )
136
+ }
113
137
}
Original file line number Diff line number Diff line change
1
+ import React from "react"
2
+
3
+ import Layout from "../components/layout"
4
+ import SEO from "../components/seo"
5
+
6
+ const Redirect = ( ) => (
7
+ < Layout >
8
+ < SEO title = "Redirect" />
9
+ < p > This should be at /pt/redirect-me/</ p >
10
+ </ Layout >
11
+ )
12
+
13
+ export default Redirect
Original file line number Diff line number Diff line change @@ -394,7 +394,7 @@ export class BaseLoader {
394
394
isPageNotFound ( rawPath ) {
395
395
const pagePath = findPath ( rawPath )
396
396
const page = this . pageDb . get ( pagePath )
397
- return page && page . notFound === true
397
+ return ! page || page . notFound
398
398
}
399
399
400
400
loadAppData ( retries = 0 ) {
Original file line number Diff line number Diff line change @@ -202,8 +202,10 @@ export class WebsocketManager {
202
202
203
203
socket . on ( `registerPath` , ( path : string ) : void => {
204
204
socket . join ( getRoomNameFromPath ( path ) )
205
- activePath = path
206
- this . activePaths . add ( path )
205
+ if ( path ) {
206
+ activePath = path
207
+ this . activePaths . add ( path )
208
+ }
207
209
} )
208
210
209
211
socket . on ( `disconnect` , ( ) : void => {
You can’t perform that action at this time.
0 commit comments