mirror of
https://github.com/flarum/framework.git
synced 2025-04-25 14:14:03 +08:00
Make the back button a functional link
This commit is contained in:
parent
025d8f691d
commit
8f4ef28475
@ -31,7 +31,10 @@ export default function boot(app) {
|
|||||||
app.alerts = m.mount(document.getElementById('alerts'), AlertManager.component());
|
app.alerts = m.mount(document.getElementById('alerts'), AlertManager.component());
|
||||||
app.history = {
|
app.history = {
|
||||||
canGoBack: () => true,
|
canGoBack: () => true,
|
||||||
back: () => window.location = '/'
|
backUrl: () => app.forum.attribute('baseUrl'),
|
||||||
|
back: function() {
|
||||||
|
window.location = this.backUrl();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
m.route.mode = 'hash';
|
m.route.mode = 'hash';
|
||||||
|
@ -85,6 +85,17 @@ export default class History {
|
|||||||
m.route(this.getTop().url);
|
m.route(this.getTop().url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the URL of the previous page.
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
backUrl() {
|
||||||
|
const secondTop = this.stack[this.stack.length - 2];
|
||||||
|
|
||||||
|
return secondTop.url;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Go to the first route in the history stack.
|
* Go to the first route in the history stack.
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import Component from 'flarum/Component';
|
import Component from 'flarum/Component';
|
||||||
import Button from 'flarum/components/Button';
|
import Button from 'flarum/components/Button';
|
||||||
|
import LinkButton from 'flarum/components/LinkButton';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `Navigation` component displays a set of navigation buttons. Typically
|
* The `Navigation` component displays a set of navigation buttons. Typically
|
||||||
@ -47,10 +48,16 @@ export default class Navigation extends Component {
|
|||||||
getBackButton() {
|
getBackButton() {
|
||||||
const {history} = app;
|
const {history} = app;
|
||||||
|
|
||||||
return Button.component({
|
return LinkButton.component({
|
||||||
className: 'Button Button--icon Navigation-back',
|
className: 'Button Button--icon Navigation-back',
|
||||||
onclick: history.back.bind(history),
|
href: history.backUrl(),
|
||||||
icon: 'chevron-left'
|
icon: 'chevron-left',
|
||||||
|
config: () => {},
|
||||||
|
onclick: e => {
|
||||||
|
if (e.shiftKey || e.ctrlKey || e.metaKey || e.which === 2) return;
|
||||||
|
e.preventDefault();
|
||||||
|
history.back();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user