Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.
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

Open

Description

@coperator

When I use ionic serve I expected the dev server to support the PathLocationStrategy, which I enabled in the app.modules.ts with

  providers: [
   ...
    { provide: LocationStrategy, useClass: PathLocationStrategy }
   ...
  ]

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.

This topic also appears in the forum, e.g.
https://forum.ionicframework.com/t/url-routing-without-hash/81140/2
https://forum.ionicframework.com/t/ionic-deeplinker-angular-html5mode-urls-without/74530/2

My current setup

cli packages:
    @ionic/cli-utils  : 1.10.2
    ionic (Ionic CLI) : 3.10.3

local packages:

    @ionic/app-scripts : 2.1.4
    Ionic Framework    : ionic-angular 3.6.1

System:

    Node : v8.4.0
    npm  : 5.3.0 
    OS   : Windows 10

Activity

  1. landru29 commented on Oct 28, 2017

    @landru29

    +1

  2. ericeslinger commented on Nov 7, 2017

    @ericeslinger

    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).

  3. longgt commented on Nov 20, 2017

    @longgt
  4. jonwestwood commented on Oct 19, 2018

    @jonwestwood

    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'
    }),

  5. jayvdb commented on Dec 19, 2018

    @jayvdb

    There is a PR #1339

    and another issue begging for this feature at #974

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions