February 1, 2023, 5:41am
Hi i am making the frontend on IC.
<a href="/next.html?param=value"></a>, in my
src folder is as follows:
But i cant go to to
next because the current url is “
http://127.0.0.1:8000/?canisterId=canisterId” and if i go to “ http://127.0.0.1:8000/next.html?param=value”, it will just throw me
400 (Bad request).
How should I change between pages on IC? Or can it only handle one-page frontend?
This is a problem only for local development. On mainnet you will be fine.
Most browsers support the ability to write
<canister id>.localhost:<port>. Does that work for you?
February 1, 2023, 8:42am
Yea i can but i have to put my
assets folder, and treat them like static files. Is this the right way? Because if this is right, does this mean that the user can see my “.js” files?
Also I know this is small problem but how do I route without having to define “.html” file extension?
February 1, 2023, 10:43am
Is this the right way?
AFAIK most projects generate the files that will end up in the
assets folder, maybe after they have been minimised. But
@kpeacock can help more with that.
Yes, that’s right. But if the files are not visible nobody would be able to use them either.
Starting with dfx 0.12.0, any
/route is aliased to
/route.html by default. Is that what you’re looking for?
February 1, 2023, 11:11am
alright got it so the arrangement will be like so:
these files above get webpacked to
i guess i will stick with this since it’s working.
yea i’m looking to do this. Even with the current arrangement like above, i still cant achieve it. I’ve tried
/next but it wont get routed to
/next.html so i have to type in the full file name. My dfx is
0.12.1. Or do I need to modify some stuffs on the default
webpack.config.js to get the routing works?
I will post the screenshots later.
February 1, 2023, 11:38am
i’ve pressed enter, it still wont get reach
now it got reached
webpack.config.js is the default, generated when one
dfx new hello
February 1, 2023, 12:19pm
Nevermind, I just looked at the commits a bit more close. The aliasing was only added in 0.12.2-beta.0, it landed in the changelog of 0.12.0 through a merge fail.
I would actually recommend you try the latest beta which you can install with
DFX_VERSION="0.13.0-beta.2" sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"
Then things should work.
If there’s too many breaking changes (there shouldn’t be much if anything at all) then using 0.12.2-beta.0 would already include the aliasing as well
February 1, 2023, 12:28pm
Alright is it stable enough for development tho? If not, it’s okay, maybe I can do the routing in the future. I will just focus on other things while waiting for 0.12.2
Anyway, have you looked at my file tree? Are the files supposed to be arranged like the screenshot above I posted? (pages that are not homepage, will be placed under
February 1, 2023, 12:48pm
IMO yes, 0.13.0-beta.2 is stable enough, I haven’t heard of any bugs since beta.0. The other beta versions were all added because a feature we want in the next release was not yet included.
I would listen to what
@kpeacock says or ask on the discord, but I think this is fine.
Yeah, definitely try out the beta build - route remapping is worth it for your purposes!
I’d also note that you can have the option to nest your content in folders, where
will route as
"foo.app/nest/index.js", depending on your preferences for how you want the files to appear