Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question : How to make "dynamic" parents? #12

Open
carnec opened this issue Oct 30, 2015 · 4 comments
Open

Question : How to make "dynamic" parents? #12

carnec opened this issue Oct 30, 2015 · 4 comments

Comments

@carnec
Copy link

carnec commented Oct 30, 2015

Hi,

Is it possible to dynamically set the parents instead of simply using their route name?
Let's say we have a collection of documents with a search page, on which the search elements are stored in the query (e.g. /documents/search?s=Some%20keywords). Search results would then be the children of the search route, using simply the search route name, breadcrumbs would look something like this:

  • Documents
  • Search <documents/search>
  • View "Name of document" <documents/search/view/id>

But the user, when clicking the "Search" breadcrumb element, would expect to go back to the search results from where he came from.

Would there be any way to pass parameters to the parent (from the "View" route) for it to be "/documents/search?s=Some%20keywords" instead of just "/documents/search" ?

Thanks for this package anyway, it's really useful and simple!

@monbro
Copy link
Owner

monbro commented Nov 22, 2015

I understand what you are saying. Unfortunately this is currently not supported. I will add this ticket as a feature request. Feel free to contribute if you find a solution for this issue.

@javascriptlove
Copy link

Hey, i know it's been a while, any luck on this?

@ziedmahdi
Copy link

@javascriptlove I forked the package and added ability to pass function for the title and parent parameters.

Router.route('/invoices/:month', {
        name: "myInvoices.show",
        parent: function () {
            if (Roles.loggedInUserCan("myInvoices.index")) {
                return "myInvoices.index";
            } else {
                return null;
            }
        },
        title: function () {
            var data = this.data();
            
            if (data) {
                return  data.month.format('YYYY-MM');
            } else {
                return '';
            }
        },
        waitOn: function () {
            var user = Meteor.user();
            if(user) {
                return [
                    subsManager.subscribe('settingsForInvoice'),
                    subsManager.subscribe('expert', user.username)
                ];
            }
        },
        data: function () {
            var wantedMonth = moment(this.params.month, 'YYYY-MM');
            var userId = Meteor.userId();
            
            if (!wantedMonth.isValid()) {
                return;
            } 
            
            if (!wantedMonth.isBefore(moment(), 'M')) {
                return;
            }
            
            if (userId) {
                var username = Meteor.users.findOne({_id: userId}, {fields: {username: 1}}).username;
                if (username) {
                    return {
                        month: wantedMonth,
                        expertUsername: username,
                    };
                }
            }
        },
        action: function () {
            if (this.data()) {
                this.render('InvoiceShow');
            } else {
                Router.go("NotFound404");
            }
        }
    });

meteor add ziedmahdi:iron-router-breadcrumb

@bluefangs
Copy link

bluefangs commented Nov 22, 2016

@monbro - Was this actually merged?
@ziedmahdi - I added your package but it does not resolve title :someRouteParam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants