iron-meteor / iron-router

A client and server side router designed specifically for Meteor.
MIT License
1.98k stars 413 forks source link

Path name with '/' inside it... #1598

Closed marcelastrapi closed 12 months ago

marcelastrapi commented 6 years ago

Hello community, I've got a problem but this is not an issue from iron-router, maybe I'm not in the good place to post this... My problem is: I make a website for a musician friend, he can create project, I have a page where all the projects are, and if you click on a project inside this page, iron router make the client go on the project page (inside the site). The problem is that he's got projects with the '/' inside the name now. So iron:router can't understand what I mean.

Router.route(`/projects/:projectName`, {
    name: "project",
    data: function() {
        return Projects.findOne({name:this.params.projectName});
    },
    waitOn: function() {
        return [
            Meteor.subscribe("Projects",{name:this.params.projectName}),
            Meteor.subscribe("Dates",{relatedProjects: this.params.projectName}),
            Meteor.subscribe("Compositions",{relatedProjects: this.params.projectName}),
            Meteor.subscribe("Videos",{relatedProjects: this.params.projectName}),
            Meteor.subscribe("Albums",{relatedProjects: this.params.projectName})
        ];
    }
});

The problem could have gone easy if I knew that before, because instead of the projectName I could just go withthe id, and I would'nt have any problem. but can't do this now, all the database is working with projectNames... So I just want to change the project page path to a safer name like (projectName.replace(/\//g,"+")) but keep the projectName for subscriptions.

I try to pass multiple arguments to Router.go, in the purpose of having the both data I need:

Router.go("project", { projectName:this.name, projectPath: this.name.replace(/\//g,"+") }); But inside the route, the route only knows the params write after the ':'. So if I wrote:

Router.route("/projects/:projectPath", .... He doesn't know anymore the projectName. I hope I'm understandable....

Thanks for your help !

nooitaf commented 6 years ago

Didn't test it, but maybe use regex * or something close to it..

Router.route("/projects/:projectPath*", ... ){}
Router.route("/projects/:projectPath+", ... ){}
Router.route("/projects/:projectPath(.*)", ... ){}

https://github.com/pillarjs/path-to-regexp#zero-or-more