You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 1, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on May 1, 2020. It is now read-only.
Ionic serve not working properly with html5mode / location path strategy #1263
The angular routing part works fine, but the dev server does not support the url rewrite back to index.html, which is a show stopper. If the missing support is intende, I would storngly propose to add this feature. For example, Angular's ng serve does support this out of the box.
I just added app.get(/^[\w\/]*$/, serveIndex); to right before the end of createHttpServer, although note that you need to put a <base href="/"> or its equivalent way at the top of index.html as well, or else the injected stuff (__ion_dev_server, etc) won't load properly.
That regex should match all alphanumeric characters plus slashes - I don't like accidentally serving the index when I meant to grab a .css file that doesn't exist (or some other static in assets), it's harder to interpret the resultant errors.
this is, of course, brittle - I manually wrote to the script in node_modules because I'm not sure I want to figure out the ins and outs of doing this the right way well enough to emit a PR over it (ideally, there'd be a commandline switch that injects the base href tag and adds the appropriate fallback route to the express devserver).
I just added app.get(/^[\w\/]*$/, serveIndex); to right before the end of createHttpServer, although note that you need to put a <base href="/"> or its equivalent way at the top of index.html as well, or else the injected stuff (__ion_dev_server, etc) won't load properly.
That regex should match all alphanumeric characters plus slashes - I don't like accidentally serving the index when I meant to grab a .css file that doesn't exist (or some other static in assets), it's harder to interpret the resultant errors.
this is, of course, brittle - I manually wrote to the script in node_modules because I'm not sure I want to figure out the ins and outs of doing this the right way well enough to emit a PR over it (ideally, there'd be a commandline switch that injects the base href tag and adds the appropriate fallback route to the express devserver).
thank you! this was such an easy fix I can't believe it doesn't happen automatically with IonicModule.forRoot(MyApp, {
locationStrategy: 'path'
}),
Activity
landru29 commentedon Oct 28, 2017
+1
ericeslinger commentedon Nov 7, 2017
I just added
app.get(/^[\w\/]*$/, serveIndex);to right before the end ofcreateHttpServer, although note that you need to put a<base href="/">or its equivalent way at the top ofindex.htmlas well, or else the injected stuff (__ion_dev_server, etc) won't load properly.That regex should match all alphanumeric characters plus slashes - I don't like accidentally serving the index when I meant to grab a .css file that doesn't exist (or some other static in assets), it's harder to interpret the resultant errors.
this is, of course, brittle - I manually wrote to the script in node_modules because I'm not sure I want to figure out the ins and outs of doing this the right way well enough to emit a PR over it (ideally, there'd be a commandline switch that injects the base href tag and adds the appropriate fallback route to the express devserver).
longgt commentedon Nov 20, 2017
#916
jonwestwood commentedon Oct 19, 2018
thank you! this was such an easy fix I can't believe it doesn't happen automatically with IonicModule.forRoot(MyApp, {
locationStrategy: 'path'
}),
jayvdb commentedon Dec 19, 2018
There is a PR #1339
and another issue begging for this feature at #974