0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Dynamic Routing Beta: StaticRoutesRouter has to respect the route name

refs #9601

- this was already working for collections or channels
- but the `routeName` was not parsed for static routes
- ensure we push the route name into the context object

e.g. /about/: about

-> name of the route is "about"
This commit is contained in:
kirrg001 2018-06-26 19:04:39 +02:00
parent 387399caca
commit c5bad55d6f
2 changed files with 20 additions and 3 deletions

View file

@ -13,6 +13,8 @@ class StaticRoutesRouter extends ParentRouter {
this.route = {value: mainRoute};
this.templates = (object.templates || []).reverse();
this.data = object.data || {query: {}, router: {}};
this.routerName = mainRoute === '/' ? 'index' : mainRoute.replace(/\//g, '');
debug(this.route.value, this.templates);
if (this.isChannel(object)) {
@ -21,7 +23,6 @@ class StaticRoutesRouter extends ParentRouter {
this.limit = object.limit;
this.order = object.order;
this.routerName = mainRoute === '/' ? 'index' : mainRoute.replace(/\//g, '');
this.controller = object.controller;
debug(this.route.value, this.templates, this.filter, this.data);
@ -80,7 +81,7 @@ class StaticRoutesRouter extends ParentRouter {
templates: this.templates,
defaultTemplate: 'default',
data: this.data.query,
context: [],
context: [this.routerName],
contentType: this.contentType
};

View file

@ -85,7 +85,23 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
type: 'custom',
templates: [],
defaultTemplate: 'default',
context: [],
context: ['about'],
data: {},
contentType: undefined
});
should.not.exist(res.locals.slug);
});
it('fn: _prepareStaticRouteContext', function () {
const staticRoutesRouter = new StaticRoutesRouter('/', {templates: []});
staticRoutesRouter._prepareStaticRouteContext(req, res, next);
next.called.should.be.true();
res.routerOptions.should.eql({
type: 'custom',
templates: [],
defaultTemplate: 'default',
context: ['index'],
data: {},
contentType: undefined
});