mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-06-16 09:41:38 +02:00
30 lines
765 B
JavaScript
30 lines
765 B
JavaScript
/**
|
|
* Handles client-side routing.
|
|
* See https://github.com/visionmedia/page.js
|
|
*/
|
|
import page from 'page.js';
|
|
|
|
/**
|
|
* Wrapper for `page.show()` with SilverStripe specific behaviour.
|
|
*/
|
|
function show(pageShow) {
|
|
return (path, state, dispatch, push) => {
|
|
// Normalise `path` so that pattern matching is more robust.
|
|
// For example if your route is '/pages' it should match when `path` is
|
|
// 'http://foo.com/admin/pages', '/pages', and 'pages'.
|
|
const el = document.createElement('a');
|
|
let pathWithSearch;
|
|
el.href = path;
|
|
pathWithSearch = el.pathname;
|
|
if (el.search) {
|
|
pathWithSearch += el.search;
|
|
}
|
|
|
|
return pageShow(pathWithSearch, state, dispatch, push);
|
|
};
|
|
}
|
|
|
|
page.show = show(page.show);
|
|
|
|
export default page;
|