File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,60 @@ VueSSR.createApp = function (context) {
152
152
}
153
153
```
154
154
155
+ ### Set status code for custom 404 error template
156
+
157
+ ` NotFound.vue `
158
+
159
+ ``` vue
160
+ <template>
161
+ <h1>404</h1>
162
+ </template>
163
+
164
+ <script>
165
+ export default {
166
+ name: 'NotFound',
167
+ };
168
+ </script>
169
+ ```
170
+
171
+ ` routes.js `
172
+
173
+ ``` javascript
174
+ import NotFound from ' /imports/ui/views/NotFound' ;
175
+
176
+ export default [
177
+ // ...
178
+ {
179
+ path: ' *' ,
180
+ name: ' not-found' ,
181
+ component: NotFound,
182
+ },
183
+ ];
184
+ ```
185
+
186
+ ` vue-ssr.js `
187
+
188
+ ``` javascript
189
+ VueSSR .createApp = function (context ) {
190
+ return new Promise ((resolve , reject ) => {
191
+ const { app , router } = CreateApp ()
192
+ // Set the URL in the router
193
+ router .push (context .url )
194
+
195
+ router .onReady (() => {
196
+ // name of wildcard route
197
+ if (router .currentRoute .name === ' not-found' ) {
198
+ context .statusCode = 404 ;
199
+ }
200
+
201
+ // ...
202
+
203
+ resolve (app)
204
+ })
205
+ })
206
+ }
207
+ ```
208
+
155
209
---
156
210
157
211
LICENCE ISC - Created by Guillaume CHAU (@Akryum )
Original file line number Diff line number Diff line change @@ -126,9 +126,11 @@ onPageLoad(sink => new Promise((resolve, reject) => {
126
126
const head = ( ( appendHtml && appendHtml . head ) || context . head ) || ''
127
127
const body = ( ( appendHtml && appendHtml . body ) || context . body ) || ''
128
128
const js = ( ( appendHtml && appendHtml . js ) || context . js ) || ''
129
+ const statusCode = ( ( appendHtml && appendHtml . statusCode ) || context . statusCode ) || 200
129
130
130
131
const script = js && `<script type="text/javascript">${ js } </script>`
131
132
133
+ sink . setStatusCode ( statusCode )
132
134
sink . renderIntoElementById ( VueSSR . outlet , html )
133
135
sink . appendToHead ( head )
134
136
sink . appendToBody ( [ body , script ] )
You can’t perform that action at this time.
0 commit comments