Set Url To Seo Friendly Title With Dashes Instead Of Id
Solution 1:
I would recommend to add anther route in addition to the existing route
when('/phones/:phoneId', {
templateUrl: 'partials/phone-detail.html',
controller: 'PhoneDetailCtrl'
}).
when('/phones/:phoneId/:title', {
templateUrl: 'partials/phone-detail.html',
controller: 'PhoneDetailCtrl'
})
For your case, you can have the following links which goes to the same page.
<ahref="http://my.url.com/articles/#66D5069C-DC67-46FC-8A51-1F15A94216D4">Start Investing</a><ahref="http://my.url.com/articles/#66D5069C-DC67-46FC-8A51-1F15A94216D4/Start+Investing">Start Investing</a>
The second will work the exactly the same as the first one
Solution 2:
You can use one of the following options, I have ordered them by my preference:
- Just use the formatted title in url and don't add anything else unless there is a collision between titles. In case of collision in title then use one of the methods below to distinguish between them. Your route would look like '/articles/:formattedTitle'. If there are multiple articles in database with same title and there is no explicit indicators of which one to pick then go ahead and pick the one created earliest.
- Create a new field called textKey, and auto populate that field uniquely based on the title of the article. e.g. one will result in http://my.url.com/articles/start-investing and the next one results in http://my.url.com/articles/start-investing-2. Your route would look like '/articles/:textKey'
- Create a new field called discriminator with default value of Null only populate it only if collision occcurs in titles. e.g. one will result in http://my.url.com/articles/start-investing and the next one results in http://my.url.com/articles/start-investing/1. Your route would look like '/articles/:formattedTitle/:discriminator'
- add both ID and title e.g. one will result in http://my.url.com/articles/start-investing/66D5069C-DC67-46FC-8A51-1F15A94216D4 and the next one results in http://my.url.com/articles/start-investing/AAE5069C-ABCD-46FC-8A51-1F15A94213A5. Your route would look like '/articles/:formattedTitle/:id'
Solution 3:
I would suggest that you use the author's username as well in the URL , so that the route will look like
.when('/article/:userID/:articletitle', {
templateUrl: './views/articles.html',
controller: 'articleCtrl'
})
This would solve the problem of different author having same article title (but now there would be a problem if the author publishes two articles with the same title. For this you can either introduce the year or month in the URL to make it unique)
Also you can create another view where author can see all their articles (route would be like)
.when('/article/:userID', {
templateUrl: './views/allArticles.html',
controller: 'allArticleCtrl'
})
Solution 4:
Using js to generate your page isn't very SEO compliant...
and also, why is-there an "article-link"
attribute in your JSON..?
If this link is not useless then you could just fetch the html content and parse the output to build your product object.
Or, better, you should rework your server-side implementation because if you are able to get an html with a GET request on http://www.thebudgetcalculator.com/start-investing.html
then you should implement it the same way for JSON api calls like http://www.thebudgetcalculator.com/api/articles/start-investing
Post a Comment for "Set Url To Seo Friendly Title With Dashes Instead Of Id"