mirror of
https://github.com/flarum/framework.git
synced 2024-12-13 07:03:35 +08:00
Support running in subdirectory with base_path config
This commit is contained in:
parent
7040ad1344
commit
0e1948cd3a
|
@ -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;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700,600);
|
||||
|
||||
@import "font-awesome.less";
|
||||
@fa-font-path: "/assets/fonts";
|
||||
@fa-font-path: "../../assets/fonts";
|
||||
|
||||
@import "normalize.less";
|
||||
@import "print.less";
|
||||
|
|
|
@ -25,6 +25,7 @@ class ForumSerializer extends Serializer
|
|||
$attributes = [
|
||||
'title' => Core::config('forum_title'),
|
||||
'baseUrl' => Core::config('base_url'),
|
||||
'basePath' => Core::config('base_path'),
|
||||
'apiUrl' => Core::config('api_url'),
|
||||
'welcomeTitle' => Core::config('welcome_title'),
|
||||
'welcomeMessage' => Core::config('welcome_message'),
|
||||
|
|
Loading…
Reference in New Issue
Block a user