mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 16:46:12 +08:00
You don't need to call buildRoutes
anymore.
Just export a function in a module called `route-map` and discourse's rotuer will do the rest. This makes it a lot easier to define routes in plugins.
This commit is contained in:
parent
b9d773ddcd
commit
6d539c0afd
|
@ -1,4 +1,4 @@
|
|||
Discourse.Route.buildRoutes(function() {
|
||||
export default function() {
|
||||
this.resource('admin', function() {
|
||||
this.route('dashboard', { path: '/' });
|
||||
this.resource('adminSiteSettings', { path: '/site_settings' }, function() {
|
||||
|
@ -60,4 +60,4 @@ Discourse.Route.buildRoutes(function() {
|
|||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,12 +1,4 @@
|
|||
/**
|
||||
Builds the routes for the application
|
||||
|
||||
@method buildRoutes
|
||||
@for Discourse.ApplicationRoute
|
||||
**/
|
||||
Discourse.Route.buildRoutes(function() {
|
||||
var router = this;
|
||||
|
||||
export default function() {
|
||||
// Error page
|
||||
this.route('exception', { path: '/exception' });
|
||||
|
||||
|
@ -20,7 +12,6 @@ Discourse.Route.buildRoutes(function() {
|
|||
this.resource('topicBySlug', { path: '/t/:slug' });
|
||||
|
||||
this.resource('discovery', { path: '/' }, function() {
|
||||
router = this;
|
||||
// top
|
||||
this.route('top');
|
||||
this.route('topCategory', { path: '/c/:slug/l/top' });
|
||||
|
@ -28,20 +19,21 @@ Discourse.Route.buildRoutes(function() {
|
|||
this.route('topCategory', { path: '/c/:parentSlug/:slug/l/top' });
|
||||
|
||||
// top by periods
|
||||
var self = this;
|
||||
Discourse.Site.currentProp('periods').forEach(function(period) {
|
||||
var top = 'top' + period.capitalize();
|
||||
router.route(top, { path: '/top/' + period });
|
||||
router.route(top + 'Category', { path: '/c/:slug/l/top/' + period });
|
||||
router.route(top + 'CategoryNone', { path: '/c/:slug/none/l/top/' + period });
|
||||
router.route(top + 'Category', { path: '/c/:parentSlug/:slug/l/top/' + period });
|
||||
self.route(top, { path: '/top/' + period });
|
||||
self.route(top + 'Category', { path: '/c/:slug/l/top/' + period });
|
||||
self.route(top + 'CategoryNone', { path: '/c/:slug/none/l/top/' + period });
|
||||
self.route(top + 'Category', { path: '/c/:parentSlug/:slug/l/top/' + period });
|
||||
});
|
||||
|
||||
// filters
|
||||
Discourse.Site.currentProp('filters').forEach(function(filter) {
|
||||
router.route(filter, { path: '/' + filter });
|
||||
router.route(filter + 'Category', { path: '/c/:slug/l/' + filter });
|
||||
router.route(filter + 'CategoryNone', { path: '/c/:slug/none/l/' + filter });
|
||||
router.route(filter + 'Category', { path: '/c/:parentSlug/:slug/l/' + filter });
|
||||
self.route(filter, { path: '/' + filter });
|
||||
self.route(filter + 'Category', { path: '/c/:slug/l/' + filter });
|
||||
self.route(filter + 'CategoryNone', { path: '/c/:slug/none/l/' + filter });
|
||||
self.route(filter + 'Category', { path: '/c/:parentSlug/:slug/l/' + filter });
|
||||
});
|
||||
|
||||
this.route('categories');
|
||||
|
@ -62,9 +54,9 @@ Discourse.Route.buildRoutes(function() {
|
|||
// User routes
|
||||
this.resource('user', { path: '/users/:username' }, function() {
|
||||
this.resource('userActivity', { path: '/activity' }, function() {
|
||||
router = this;
|
||||
var self = this;
|
||||
_.map(Discourse.UserAction.TYPES, function (id, userAction) {
|
||||
router.route(userAction, { path: userAction.replace('_', '-') });
|
||||
self.route(userAction, { path: userAction.replace('_', '-') });
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -99,4 +91,4 @@ Discourse.Route.buildRoutes(function() {
|
|||
this.resource('badges', function() {
|
||||
this.route('show', {path: '/:id/:slug'});
|
||||
});
|
||||
});
|
||||
}
|
|
@ -90,7 +90,23 @@ Discourse.Route.reopenClass({
|
|||
|
||||
mapRoutes: function() {
|
||||
Discourse.Router.map(function() {
|
||||
routeBuilder.call(this);
|
||||
var router = this;
|
||||
|
||||
if (routeBuilder) {
|
||||
Ember.warn("The Discourse `routeBuilder` is deprecated. Export a `route-map` instead");
|
||||
routeBuilder.call(router);
|
||||
}
|
||||
|
||||
// If a module is defined as `route-map` in discourse or a plugin, its routes
|
||||
// will be built automatically.
|
||||
Ember.keys(requirejs._eak_seen).forEach(function(key) {
|
||||
if (/route-map$/.test(key)) {
|
||||
var module = require(key, null, null, true);
|
||||
if (!module) { throw new Error(key + ' must export a map function.'); }
|
||||
module.default.call(router);
|
||||
}
|
||||
});
|
||||
|
||||
this.route('unknown', {path: '*path'});
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user