1
0
mirror of https://github.com/flarum/core.git synced 2025-08-01 14:10:37 +02:00

Support running in subdirectory with base_path config

This commit is contained in:
Toby Zerner
2015-08-13 12:58:59 +09:30
parent 7040ad1344
commit 0e1948cd3a
5 changed files with 13 additions and 5 deletions

View File

@@ -254,8 +254,9 @@ export default class App {
route(name, params = {}) {
const url = this.routes[name].path.replace(/:([^\/]+)/g, (m, key) => extract(params, key));
const queryString = m.route.buildQueryString(params);
const prefix = m.route.mode === 'pathname' ? app.forum.attribute('basePath') : '';
return url + (queryString ? '?' + queryString : '');
return prefix + url + (queryString ? '?' + queryString : '');
}
/**

View File

@@ -4,9 +4,10 @@
*
* @see https://lhorie.github.io/mithril/mithril.route.html#defining-routes
* @param {Object} routes
* @param {String} [basePath]
* @return {Object}
*/
export default function mapRoutes(routes) {
export default function mapRoutes(routes, basePath = '') {
const map = {};
for (const key in routes) {
@@ -14,7 +15,7 @@ export default function mapRoutes(routes) {
if (route.component) route.component.props.routeName = key;
map[route.path] = route.component;
map[basePath + route.path] = route.component;
}
return map;