File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed
Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -58,20 +58,19 @@ func main() {
5858
5959 // Application (SPA - Reactjs)
6060 {
61- // We can use a prefix for the SPA app, as long as we specify the same prefix in the "homepage" field
62- // in the package.json file...
63- // ```
64- // {
65- // "homepage": "/app"
66- // }
67- //
68- // $ npm run build
69- // ```
7061 prefix := "/app"
71- // Create a subrouter at the prefix path
72- appSubRouter := router .PathPrefix (prefix ).Subrouter ()
73- // Create the app route handler with the subrouter and the prefix.
74- newAppRouter (prefix , appSubRouter )
62+
63+ // The Single-Page-Application should be delivered from the prefix path with a trailing '/'.
64+ // This is important to ensure that relative paths used within the SPA inherit the full path,
65+ // including the prefix.
66+ spaPrefix := prefix + "/"
67+ appSubRouter := router .PathPrefix (spaPrefix ).Subrouter () // Subrouter for SPA
68+ newAppRouter (prefix , appSubRouter ) // Handler for SPA
69+
70+ // For the 'bare' prefix path (with no trailing '/') we redirect to add the trailing '/',
71+ // being careful to use a relative path here.
72+ redirectionPrefix := "." + spaPrefix
73+ router .PathPrefix (prefix ).Handler (http .RedirectHandler (redirectionPrefix , http .StatusTemporaryRedirect ))
7574 }
7675
7776 // static assets
You can’t perform that action at this time.
0 commit comments