Where will you implement the correspondance between RESTfull urls & SEO urls ?
We plan to use react & react-router for a website that is content oriented (vs app oriented).
A seo urls is one of those that search engines likes : mydomain.com/my-super-title-that-increase-my-ranking instead of mydomain.com/posts/42
In term of design, will you implement this kind of thing in react-router (& the Path util) or will you delegate this to rewrite rules in a webserver.
Thanks for your advices.
Why do you suggest it requires special support from router? I imagine you would need a route handler that handles /:slug and resolves transition when it has fetched the data for that post, just like you'd do /posts/:id.
Probably I don't understand the design and behaviours very well, but for me, the transitions shows the both paths. If I request on /posts/:id, I probably want to make a 301 request to /:slug. If I request a /:slug-old-one because the title of the page change, I have a 301 to handle too.
Could I make it with transitions ?
Are you talking about client rendering or server rendering? You can use RR for both, or just for client.
You need to decide which URL is canonical: the one with the ID or the one with the slug. If it's the one with the slug, call transition.redirect from your PostByIdRouteHandler's willTransitionTo once you have fetched the slug for a post ID.
The 301 is for server rendering (http response code for redirect). For the client rendering the behaviour will be something bit different, because the generated links should be the slug ones. But I have to validate the detailed behaviours with a SEO specialist. But what your are talking about is making sense to me, I will try something like that.
The redirect works only for client side because of the use of location in createRouter.js and specially handleAbort so I can't use it to inform bots the url to register
You can pass your own abort handler with Router.create (options.onAbort). I haven't done much server-side rendering myself with react-router, but it seems to me one option would be to do handle redirects like this:
function onAbort(reason) {
if(reason instanceof Redirect){
var newPath = router.makePath(reason.to, reason.params, reason.query);
serverResponse.redirect(newPath);
}
..
}
Thanks both ! I try something with all of that but I don't like pretty much the result. It seems too me that it's too complicated, too much places to impact to make it work.
To explain what I have tried, for the seo it's seems to me that the restfull urls have to be hidden, only a url with dash should be displayed and answer 200 (OK). I have'nt pushed the concept to have a SeoLink component but it's probably needed.
<Route path="*" handler={SlugHandler}/>
Define that route very last, then do whatever parsing, data fetching you need in there since you've got at least some URLs that are completely unknown to your static program, the router can't help you map them.