mirror of
https://github.com/flarum/framework.git
synced 2024-12-12 06:03:39 +08:00
Implement default route config setting
This commit is contained in:
parent
dfdfae7b6d
commit
bb89ef276f
|
@ -82,7 +82,7 @@ export default class BasicsPage extends Component {
|
|||
m.redraw(true);
|
||||
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>
|
||||
]
|
||||
})}
|
||||
|
|
|
@ -8,8 +8,6 @@ import mapRoutes from 'flarum/utils/mapRoutes';
|
|||
import Navigation from 'flarum/components/Navigation';
|
||||
import HeaderPrimary from 'flarum/components/HeaderPrimary';
|
||||
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 ModalManager from 'flarum/components/ModalManager';
|
||||
import AlertManager from 'flarum/components/AlertManager';
|
||||
|
@ -21,14 +19,25 @@ import AlertManager from 'flarum/components/AlertManager';
|
|||
* @param {ForumApp} 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.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-primary'), HeaderPrimary.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.drawer = new Drawer();
|
||||
|
|
|
@ -12,7 +12,7 @@ import NotificationsPage from 'flarum/components/NotificationsPage';
|
|||
*/
|
||||
export default function(app) {
|
||||
app.routes = {
|
||||
'index': {path: '/', component: IndexPage.component()},
|
||||
'index': {path: '/all', component: IndexPage.component()},
|
||||
'index.filter': {path: '/:filter', component: IndexPage.component()},
|
||||
|
||||
'discussion.id': {path: '/d/:id', component: DiscussionPage.component()},
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* rather than the previous discussion.
|
||||
*/
|
||||
export default class History {
|
||||
constructor() {
|
||||
constructor(defaultRoute) {
|
||||
/**
|
||||
* The stack of routes that have been navigated to.
|
||||
*
|
||||
|
@ -18,11 +18,6 @@ export default class History {
|
|||
* @protected
|
||||
*/
|
||||
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', '/');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,7 +31,8 @@ class ForumSerializer extends Serializer
|
|||
'themePrimaryColor' => Core::config('theme_primary_color'),
|
||||
'canView' => $forum->can($this->actor, 'view'),
|
||||
'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()) {
|
||||
|
|
|
@ -53,7 +53,7 @@ class ForumServiceProvider extends ServiceProvider
|
|||
$this->app->instance('flarum.forum.routes', $routes = new RouteCollection);
|
||||
|
||||
$routes->get(
|
||||
'/',
|
||||
'/all',
|
||||
'flarum.forum.index',
|
||||
$this->action('Flarum\Forum\Actions\IndexAction')
|
||||
);
|
||||
|
@ -113,6 +113,14 @@ class ForumServiceProvider extends ServiceProvider
|
|||
);
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user