1
0
mirror of https://github.com/flarum/core.git synced 2025-07-30 21:20:24 +02:00

Implement default route config setting

This commit is contained in:
Toby Zerner
2015-08-06 12:18:59 +09:30
parent c8084c3925
commit 80e13ae289
6 changed files with 27 additions and 14 deletions

View File

@@ -82,7 +82,7 @@ export default class BasicsPage extends Component {
m.redraw(true); m.redraw(true);
this.$('.BasicsPage-homePage input').select(); this.$('.BasicsPage-homePage input').select();
}}/> }}/>
Custom <input className="FormControl" value={this.values.default_route()} onchange={m.withAttr('value', this.values.default_route)} style={this.values.default_route() !== '/all' ? 'margin-top: 5px' : 'display:none'}/> Custom <input className="FormControl" value={this.values.default_route()} oninput={m.withAttr('value', this.values.default_route)} style={this.values.default_route() !== '/all' ? 'margin-top: 5px' : 'display:none'}/>
</label> </label>
] ]
})} })}

View File

@@ -8,8 +8,6 @@ import mapRoutes from 'flarum/utils/mapRoutes';
import Navigation from 'flarum/components/Navigation'; import Navigation from 'flarum/components/Navigation';
import HeaderPrimary from 'flarum/components/HeaderPrimary'; import HeaderPrimary from 'flarum/components/HeaderPrimary';
import HeaderSecondary from 'flarum/components/HeaderSecondary'; import HeaderSecondary from 'flarum/components/HeaderSecondary';
import FooterPrimary from 'flarum/components/FooterPrimary';
import FooterSecondary from 'flarum/components/FooterSecondary';
import Composer from 'flarum/components/Composer'; import Composer from 'flarum/components/Composer';
import ModalManager from 'flarum/components/ModalManager'; import ModalManager from 'flarum/components/ModalManager';
import AlertManager from 'flarum/components/AlertManager'; import AlertManager from 'flarum/components/AlertManager';
@@ -21,14 +19,25 @@ import AlertManager from 'flarum/components/AlertManager';
* @param {ForumApp} app * @param {ForumApp} app
*/ */
export default function boot(app) { export default function boot(app) {
// Get the configured default route and update that route's path to be '/'.
// Push the homepage as the first route, so that the user will always be
// able to click on the 'back' button to go home, regardless of which page
// they started on.
const defaultRoute = app.forum.attribute('defaultRoute');
for (const i in app.routes) {
if (app.routes[i].path === defaultRoute) {
app.routes[i].path = '/';
app.history.push(i, '/');
}
}
m.startComputation(); m.startComputation();
m.mount(document.getElementById('app-navigation'), Navigation.component({className: 'App-backControl', drawer: true})); m.mount(document.getElementById('app-navigation'), Navigation.component({className: 'App-backControl', drawer: true}));
m.mount(document.getElementById('header-navigation'), Navigation.component()); m.mount(document.getElementById('header-navigation'), Navigation.component());
m.mount(document.getElementById('header-primary'), HeaderPrimary.component()); m.mount(document.getElementById('header-primary'), HeaderPrimary.component());
m.mount(document.getElementById('header-secondary'), HeaderSecondary.component()); m.mount(document.getElementById('header-secondary'), HeaderSecondary.component());
m.mount(document.getElementById('footer-primary'), FooterPrimary.component());
m.mount(document.getElementById('footer-secondary'), FooterSecondary.component());
app.pane = new Pane(document.getElementById('app')); app.pane = new Pane(document.getElementById('app'));
app.drawer = new Drawer(); app.drawer = new Drawer();

View File

@@ -12,7 +12,7 @@ import NotificationsPage from 'flarum/components/NotificationsPage';
*/ */
export default function(app) { export default function(app) {
app.routes = { app.routes = {
'index': {path: '/', component: IndexPage.component()}, 'index': {path: '/all', component: IndexPage.component()},
'index.filter': {path: '/:filter', component: IndexPage.component()}, 'index.filter': {path: '/:filter', component: IndexPage.component()},
'discussion.id': {path: '/d/:id', component: DiscussionPage.component()}, 'discussion.id': {path: '/d/:id', component: DiscussionPage.component()},

View File

@@ -10,7 +10,7 @@
* rather than the previous discussion. * rather than the previous discussion.
*/ */
export default class History { export default class History {
constructor() { constructor(defaultRoute) {
/** /**
* The stack of routes that have been navigated to. * The stack of routes that have been navigated to.
* *
@@ -18,11 +18,6 @@ export default class History {
* @protected * @protected
*/ */
this.stack = []; this.stack = [];
// Push the homepage as the first route, so that the user will always be
// able to click on the 'back' button to go home, regardless of which page
// they started on.
this.push('index', '/');
} }
/** /**

View File

@@ -31,7 +31,8 @@ class ForumSerializer extends Serializer
'themePrimaryColor' => Core::config('theme_primary_color'), 'themePrimaryColor' => Core::config('theme_primary_color'),
'canView' => $forum->can($this->actor, 'view'), 'canView' => $forum->can($this->actor, 'view'),
'canStartDiscussion' => $forum->can($this->actor, 'startDiscussion'), 'canStartDiscussion' => $forum->can($this->actor, 'startDiscussion'),
'allowSignUp' => (bool) Core::config('allow_sign_up') 'allowSignUp' => (bool) Core::config('allow_sign_up'),
'defaultRoute' => Core::config('default_route')
]; ];
if ($this->actor->isAdmin()) { if ($this->actor->isAdmin()) {

View File

@@ -53,7 +53,7 @@ class ForumServiceProvider extends ServiceProvider
$this->app->instance('flarum.forum.routes', $routes = new RouteCollection); $this->app->instance('flarum.forum.routes', $routes = new RouteCollection);
$routes->get( $routes->get(
'/', '/all',
'flarum.forum.index', 'flarum.forum.index',
$this->action('Flarum\Forum\Actions\IndexAction') $this->action('Flarum\Forum\Actions\IndexAction')
); );
@@ -113,6 +113,14 @@ class ForumServiceProvider extends ServiceProvider
); );
event(new RegisterForumRoutes($routes)); event(new RegisterForumRoutes($routes));
$settings = $this->app->make('Flarum\Core\Settings\SettingsRepository');
$routes->get(
'/',
'flarum.forum.default',
$routes->getRouteData()[0]['GET'][$settings->get('default_route')]
);
} }
protected function action($class) protected function action($class)