Add routes to existing view

Hi,

and thanks for this Framework7 community !
I’m trying to create an app based on Framework7 that would let you use different themes, placed in different folders, like

/www/themes/project1
/www/themes/project2

I would like to automatically add routes to my main view in this fashion :

{
path: ‘/themes/project1’,
url: ‘./themes/project1/index.html’
}

(I understand that if I simply put a link to /themes/projectName/index.html it won’t work automatically)
So is that even possible to add routes to my existing main view, so that in my virtual list of projects I can click on a simple link like

Project1

and be redirected to the index file in the project1 folder in themes folder ?

Static routing I use in routes.js work as expected, but I cannot add routes to an existing view by the means shown on the guide.

Thanks in advance !

Carlo

var app=new Framework7({/*params*/});

app.routes.push({
  path:'/about/',
  url:'./pages/about.html'
});

app.routes.push({
  path:'/users/',
  templateUrl:'./pages/users.html',
  on:{
    pageInit:function(e,page){
    }
  }
});

Hi and thanks,

that’s actually what I tried in the first place, pushing the routes to the array, but it doesn’t work.
If I console.log the app’s routes I’ve automatically created, and I juste copy and paste them in routes.js, they do work without any problem. For instance I take :

{path: “/themes/project1/”, url: “./themes/project1/index.html”}

generated by my code, if I put it in routes.js it works, otherwise not.

So the routes are right, they are pushed in the right place (I can see the other working routes defined in routes.js), but maybe I have to “reinitialise” the router or do some other action on the app object ?

Thanks for any suggestion

init the view after the push

1 Like

If you push routes after View init then push them to view.routes

Hi, pushing routes after View init does not seem to work, while if I add them BEFORE view init it works. I would like to be able to push them after but as of now I solved the problem by adding them before.

Thanks to everyone !

What works for me

a) pushing new routes to app.routes
b) mainView.destroy();
c) mainView = app.views.create(’.view-main’);

Pushing routes to mainView.routes causes some issues afterwards (e.g. multiple page transitions: pages seems to be dublicated, header is mixed up in case the old pages are not deleted).

Best regards
Andreas