aurelia / new

The Aurelia 2 scaffolding repo used by our tools to setup new projects.
MIT License
38 stars 18 forks source link

generated index.ejs does not play nice with electron #24

Closed xenoterracide closed 4 years ago

xenoterracide commented 4 years ago

instead of <base href="/" /> it needs to be <base href="./" /> otherwise you'll get this.

GET file:///entry-bundle.js net::ERR_FILE_NOT_FOUND

to reproduce

npx makes aurelia test-app -s
cd test-app
npm run build
npm install --save @capacitor/core @capacitor/cli
npx cap init                                                     # defaults are fine
sed -ie s/www/dist/g capacitor.config.json                # use dist as the web root
npx cap add electron
npx cap copy
npx cap open electron

you will see a black screen of death and in the console there will be the afformentioned error

3cp commented 4 years ago

You are not supposed to put relative path inside <base>. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

What you have is different issue I think.

xenoterracide commented 4 years ago

https://github.com/ionic-team/capacitor/issues/1037 I'm open to alternative fixes, since I've provided reproduction steps, but what is currently there does not work

3cp commented 4 years ago

I think I am wrong about <base>.

The base URL to be used throughout the document for relative URLs. Absolute and relative URLs are allowed.

But in Aurelia, we have to use absolute path inside <base> to support routes.

Because inside a front-end route http://localhost/product/1, <base href="./"> does not work for us.

3cp commented 4 years ago

If the app and unit tests and cypress tests all work as expected, I guess this repo might not correct place to fix your electron setup. But I have no much experience on electron anyway, I might be wrong.

3cp commented 4 years ago

The <base href="./"> is not a fix. As I said, it will break Aurelia app with pushState routes, unless @jwx did something different from Aurelia 1.

xenoterracide commented 4 years ago

pushState (if I understand you correctly) does not work in electron see https://github.com/aurelia/aurelia/issues/852

3cp commented 4 years ago

But we cannot use your fix because this repo is mainly to support Aurelia app (majority of users will use router), not electron.

3cp commented 4 years ago

Since you knew why to make your setup work, you can mutate the app after it was generated. I guess simply remove <base> element will work for you too.

xenoterracide commented 4 years ago

I'm using router, currently it seems fine, but maybe I don't have the right thing done, I don't have a route like product/1 for example. I see someone also suggesting '' maybe that is the better fix. I'll try it.

My app needs to support ALL of the platforms and things like product/1 will need to work in all of them.

3cp commented 4 years ago

My example is for when use click a menu to <a href="another/page"> from /product/1 page, the <base href="./"> will tell browser to route to /product/another/page (or /product/1/another/page I am not sure), not /another/page (<base href="/"> will give that correct result).

You need to test your other base fix for the above case.

xenoterracide commented 4 years ago

<base href=""> works too, if that's any better

xenoterracide commented 4 years ago

we can leave this open for now, @jwx has some insight here as well... all I really have right now is that href="/" causes issues other SPA platforms

curious, what happens if you serve an app root at http://localhost/foo and you're using / will that still work correctly?

3cp commented 4 years ago

I tested <base href=""> in au1, it broke the reload if I reload a page with some route /not/root, it might be due to I use lots of bare url resources link in my app.

3cp commented 4 years ago

Let's follow up this issue in the aurelia/aurelia#852, might be an opportunity to remove <base> from au2's router requirement. Actually I never heard about <base> tag before using Aurelia.

xenoterracide commented 4 years ago

I don't actually think that's the right place to discuss this as it confuses the issue, since there are 2 separate issues. In discord I got this from @jwx

Jurgen: Right. So 1) the au2 router doesn't use so that can safely be removed

and doing that works for me

jwx commented 4 years ago

To be clear: the router in Aurelia 2 doesn't use or require the <base> tag.

3cp commented 4 years ago

Great! Let's just remove it!