Zeronet: Request: some kind of routing in a sites content.json

Created on 11 Oct 2017  路  6Comments  路  Source: HelloZeroNet/ZeroNet

Hi

I'm currently fiddling about with ZeroNet trying to build a single page application and have gotten to the point where I've got to start thinking about the routing. When using a more traditional client/server setup you'd configure the server to serve the same page regardless of the url given and let the clientside javascript handle showing the correct content. As far as I know this isn't possible with ZeroNet, it will always try to serve the file the url is pointing to.

Just to see if I could get the clientside routing thing to work if I could get ZeroNet to serve the right file, I hacked in the option (gist) for a zite to fall back on a configured path if the requested file couldn't be found. It worked, so it seems to me that giving a zite creator some rudimentary control over which file is served for which url could be useful.

Thanks,

Wieke

Most helpful comment

@krixano Sweet. I'm using Vue as well and just noticed that vue-router tries to refresh the site when I hit forward. I'm going to give your router a try.

@HelloZeroNet Having some kind of fallback page would probably be sufficient. It's not like you could actually do something with complex routing in zeronet, right?

All 6 comments

You can use javascript client-side routing. I created a library that helps with this called ZeroFrame Router. Here's a basic demo zite. most of my zeronet projects use the ZeroFrame Router along with the new Vuejs plugin I made so you can more easily use the plugin with vuejs. The best project you can look at to see how I use all this in a real zite is probably ZeroMedium.

Under the hood, all it does is run zeroframe's wrapperPushState and wrapperPopState commands and when you click a link to route to a page, it will run your controller function. This I believe is similar to how other zites are doing routing. If using the Vuejs plugin, it will switch a component you put into your root template to the component you defined for the route.

Right now the sites routing using the "?" character, eg.:
http://127.0.0.1:43110/me.zeronetwork.bit/?Post/12h51ug6CcntU2aiBjhP8Ns2e5VypbWWtv/12gAes6NzDS9E2q6Q1UXrpUdbPS6nvuBPu/1507834329

Probably I would avoid complex routing rules in the client, but adding a default page for non-existent urls would be a good idea and you could also use it to parse the page url and route using javascript.

@krixano Sweet. I'm using Vue as well and just noticed that vue-router tries to refresh the site when I hit forward. I'm going to give your router a try.

@HelloZeroNet Having some kind of fallback page would probably be sufficient. It's not like you could actually do something with complex routing in zeronet, right?

@Wieke As a forewarning, my router is not really the best right now (there are things that need to be fixed, including with the vuejs plugin). However, it is fairly usable.

Please see issue #1548 and the associated PR #1549

@HelloZeroNet Can this be closed in favor of #1548?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DaniellMesquita picture DaniellMesquita  路  3Comments

yurkobb picture yurkobb  路  3Comments

ghost picture ghost  路  4Comments

imachug picture imachug  路  3Comments

Forbo picture Forbo  路  3Comments