mirror of
https://github.com/flarum/core.git
synced 2025-07-31 21:50:50 +02:00
Support running in subdirectory with base_path config
This commit is contained in:
@@ -45,8 +45,13 @@ export default function boot(app) {
|
||||
app.modal = m.mount(document.getElementById('modal'), ModalManager.component());
|
||||
app.alerts = m.mount(document.getElementById('alerts'), AlertManager.component());
|
||||
|
||||
const basePath = app.forum.attribute('basePath');
|
||||
m.route.mode = 'pathname';
|
||||
m.route(document.getElementById('content'), '/', mapRoutes(app.routes));
|
||||
m.route(
|
||||
document.getElementById('content'),
|
||||
basePath + '/',
|
||||
mapRoutes(app.routes, basePath)
|
||||
);
|
||||
|
||||
m.endComputation();
|
||||
|
||||
|
@@ -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 : '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user