Make page title a value from database in angular uirouter?


#1

Hello there meteor forum

I’m creating an FAQ. I’m trying to make it SEO friendly so if someone types a question related to my app I would like it to appear in the search result.

I’m trying to make the title be dynamically with the value from the database but I’ve failed to achieve it.

I got it somewhat working but it doesn’t get the current title, it just takes the old one from the previous visited state and not the one currently visiting.

My question would be.

How do I make a FAQ section SEO friendly on angular-meteor?

Thanks!


#2

I don’t know uirouter, but I do this in an app I made:

Template:
<h1>{{pageTitle}}</h1>

Helper:

Template.body.helpers({
    pageTitle: function(){
        return Session.get("pageTitle");
    }
});

in the router:

onAfterAction: function(){
        switch(Router.current().route.path()){
            case "/path1":
                Session.set("pageTitle", "Frank");
                break;
            case "/path2":
                Session.set("pageTitle", "Zappa");
                break;
          ...

that function could of course be:

onAfterAction: function(){
     Session.set("pageTitle, 
     MyTitles.findOne({path: Router.current().route.path()})
}

if you want to use a db