I think you should first plan your URL patterns carefully. It seems not a good idea to have /{{post_name}}
and /posttemplate
at the same level.
Maybe you could try to add a path prefix to all your individual articles, like /post/:post_name
.
Then you can just add this to your router config:
.when("/post/:post_name", {
controller: 'DynamicRouteController',
templateUrl: 'templates/posttemplate.html'
}
Then in DynamicRouteController
, read post_name
from $routeParams
and map it to your post IDs. You may add something like a unique_name
field to your posts, in which stores the URL (/post/post_name) you want it to be accessible from.
Or, if you really want, you can also put them the same level. Just make sure that the "catch-all" item is at the end of your router configs.
And, if you want, you can definitely save the router configs into a JSON file. Just iterate over an array of config items and pass them to when()
.