@@ -30,32 +30,39 @@ const steps = new WillItCorsStore();
3030export const Steps = observer ( ( { currentStep } : { currentStep : WillItCorsSteps } ) => {
3131 const router = useRouter ( ) ;
3232
33+ // If you end up directly on a step without having completed the path this session (e.g.
34+ // if you refresh the page or navigate there directly), we redirect you to the root.
35+ if ( currentStep !== 'source-url' && ! steps . sourceUrl ) {
36+ router . push ( '/will-it-cors/' ) ;
37+ return null ;
38+ }
39+
3340 switch ( currentStep ) {
3441 case 'source-url' :
3542 return (
3643 < SourceUrlQuestion
37- value = { steps . sourceUrl }
44+ value = { steps . sourceUrl || 'https://' }
3845 onChange = { newValue => {
3946 steps . setSourceUrl ( newValue ) ;
4047 } }
41- onNext = { ( ) => router . push ( '/will-it-cors/target-url' ) }
48+ onNext = { ( ) => router . push ( '/will-it-cors/target-url/ ' ) }
4249 />
4350 ) ;
4451
4552 case 'target-url' :
4653 return (
4754 < TargetUrlQuestion
48- value = { steps . targetUrl }
55+ value = { steps . targetUrl || 'https://' }
4956 onChange = { newValue => {
5057 steps . setTargetUrl ( newValue ) ;
5158 } }
5259 onNext = { ( ) => {
5360 if ( ! steps . isCorsRequest ) {
54- router . push ( '/will-it-cors/not-cors' ) ;
61+ router . push ( '/will-it-cors/not-cors/ ' ) ;
5562 } else if ( steps . isMixedContentRequest ) {
56- router . push ( '/will-it-cors/mixed-content' ) ;
63+ router . push ( '/will-it-cors/mixed-content/ ' ) ;
5764 } else {
58- router . push ( '/will-it-cors/method' ) ;
65+ router . push ( '/will-it-cors/method/ ' ) ;
5966 }
6067 } }
6168 />
@@ -79,7 +86,7 @@ export const Steps = observer(({ currentStep }: { currentStep: WillItCorsSteps }
7986 onChange = { newValue => {
8087 steps . setMethod ( newValue ) ;
8188 } }
82- onNext = { ( ) => router . push ( '/will-it-cors/request-extras' ) }
89+ onNext = { ( ) => router . push ( '/will-it-cors/request-extras/ ' ) }
8390 sourceOrigin = { steps . sourceOrigin ?? 'https://' }
8491 targetOrigin = { steps . targetOrigin ?? 'http://' }
8592 />
@@ -102,11 +109,11 @@ export const Steps = observer(({ currentStep }: { currentStep: WillItCorsSteps }
102109 } }
103110 onNext = { ( ) => {
104111 if ( steps . method === 'POST' && steps . contentType === undefined ) {
105- router . push ( '/will-it-cors/content-type' ) ;
112+ router . push ( '/will-it-cors/content-type/ ' ) ;
106113 } else if ( steps . isSimpleCorsRequest ) {
107- router . push ( '/will-it-cors/simple-cors' ) ;
114+ router . push ( '/will-it-cors/simple-cors/ ' ) ;
108115 } else {
109- router . push ( '/will-it-cors/preflight' ) ;
116+ router . push ( '/will-it-cors/preflight/ ' ) ;
110117 }
111118 } }
112119 />
@@ -125,16 +132,16 @@ export const Steps = observer(({ currentStep }: { currentStep: WillItCorsSteps }
125132 } }
126133 onNext = { ( ) => {
127134 if ( steps . isSimpleCorsRequest ) {
128- router . push ( '/will-it-cors/simple-cors' ) ;
135+ router . push ( '/will-it-cors/simple-cors/ ' ) ;
129136 } else {
130- router . push ( '/will-it-cors/preflight' ) ;
137+ router . push ( '/will-it-cors/preflight/ ' ) ;
131138 }
132139 } }
133140 />
134141 ) ;
135142
136143 case 'simple-cors' :
137- return < SimpleCorsRequest onNext = { ( ) => router . push ( '/will-it-cors/server-response' ) } /> ;
144+ return < SimpleCorsRequest onNext = { ( ) => router . push ( '/will-it-cors/server-response/ ' ) } /> ;
138145
139146 case 'server-response' :
140147 return (
@@ -151,9 +158,9 @@ export const Steps = observer(({ currentStep }: { currentStep: WillItCorsSteps }
151158 } }
152159 onNext = { ( ) => {
153160 if ( steps . isServerResponseReadable ) {
154- router . push ( '/will-it-cors/request-success' ) ;
161+ router . push ( '/will-it-cors/request-success/ ' ) ;
155162 } else {
156- router . push ( '/will-it-cors/request-failure' ) ;
163+ router . push ( '/will-it-cors/request-failure/ ' ) ;
157164 }
158165 } }
159166 />
@@ -174,18 +181,18 @@ export const Steps = observer(({ currentStep }: { currentStep: WillItCorsSteps }
174181 sourceOrigin = { steps . sourceOrigin ?? 'https://' }
175182 responseHeaders = { steps . serverResponseHeaders }
176183 sendCredentials = { steps . sendCredentials }
177- onNext = { ( ) => router . push ( '/will-it-cors/show-code' ) }
184+ onNext = { ( ) => router . push ( '/will-it-cors/show-code/ ' ) }
178185 />
179186 ) ;
180187
181188 case 'show-code' :
182189 return < ShowCode code = { steps . exampleCode } /> ;
183190
184191 case 'preflight' :
185- return < PreflightRequest onNext = { ( ) => router . push ( '/will-it-cors/preflight-response' ) } /> ;
192+ return < PreflightRequest onNext = { ( ) => router . push ( '/will-it-cors/preflight-response/ ' ) } /> ;
186193
187194 case 'preflight-success' :
188- return < ServerAllowsPreflightRequest onNext = { ( ) => router . push ( '/will-it-cors/server-response' ) } /> ;
195+ return < ServerAllowsPreflightRequest onNext = { ( ) => router . push ( '/will-it-cors/server-response/ ' ) } /> ;
189196
190197 case 'preflight-response' :
191198 return (
@@ -202,9 +209,9 @@ export const Steps = observer(({ currentStep }: { currentStep: WillItCorsSteps }
202209 } }
203210 onNext = { ( ) => {
204211 if ( steps . isPreflightSuccessful ) {
205- router . push ( '/will-it-cors/preflight-success' ) ;
212+ router . push ( '/will-it-cors/preflight-success/ ' ) ;
206213 } else {
207- router . push ( '/will-it-cors/preflight-failure' ) ;
214+ router . push ( '/will-it-cors/preflight-failure/ ' ) ;
208215 }
209216 } }
210217 />
0 commit comments