I'm trying to create an app in which the route names are dynamically loaded from the database via session, and the user can manually change them via an admin panel.
So, for example, the default route name is stored in my db as "projects". I load it into Session and add it to a "Routes" array like so:
Of course, I'm doing this outside of Meteor.startup, as suggested. So far, so good. Going to the url '/projects' calls my listProjects template. So I can load route URLs out of the db at server startup perfectly well. Groovy!
However, as I said, I have an admin panel where the user can type in what they want this label to be. For example, a user could change 'projects' to 'artists'. Does this make sense? It's a custom CMS, so the user needs to be able to change the URLs (and therefore routes) to suit their needs.
User types new route names in the admin form, hits submit. The db and session get updated fine, as does the Routes array itself (I check by console.logging it).
However, when I try to navigate to the new url (for example 'http://localhost:3000/artists' instead of 'http://localhost:3000/projects') the {{renderPage}} section is blank. If I hit refresh, the browser shows me my 404 template. If I restart the server, all works again.
I'm calling the setRoutes() function I created to do this when the admin form is updated, as well as under Deps.autorun. But I'm sure I'm putting it in the wrong place.
So the underlying question is: how can I dynamically change the named routes Router uses, and trigger Router to recognize the new routes?
Hi there,
I'm trying to create an app in which the route names are dynamically loaded from the database via session, and the user can manually change them via an admin panel.
So, for example, the default route name is stored in my db as "projects". I load it into Session and add it to a "Routes" array like so:
then I do
Of course, I'm doing this outside of Meteor.startup, as suggested. So far, so good. Going to the url '/projects' calls my listProjects template. So I can load route URLs out of the db at server startup perfectly well. Groovy!
However, as I said, I have an admin panel where the user can type in what they want this label to be. For example, a user could change 'projects' to 'artists'. Does this make sense? It's a custom CMS, so the user needs to be able to change the URLs (and therefore routes) to suit their needs.
User types new route names in the admin form, hits submit. The db and session get updated fine, as does the Routes array itself (I check by console.logging it).
However, when I try to navigate to the new url (for example 'http://localhost:3000/artists' instead of 'http://localhost:3000/projects') the {{renderPage}} section is blank. If I hit refresh, the browser shows me my 404 template. If I restart the server, all works again.
I'm calling the setRoutes() function I created to do this when the admin form is updated, as well as under Deps.autorun. But I'm sure I'm putting it in the wrong place.
So the underlying question is: how can I dynamically change the named routes Router uses, and trigger Router to recognize the new routes?