本文整理匯總了TypeScript中mithril.route.set方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript route.set方法的具體用法?TypeScript route.set怎麽用?TypeScript route.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mithril.route
的用法示例。
在下文中一共展示了route.set方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: resolve
.catch(err => {
if (!window.username && err.message.indexOf("authorized") >= 0) {
notifications.push("error", err.message);
m.route.set("/login", { continue: requestedPath });
}
state = { error: err.message };
resolve();
});
示例2:
onmatch: () => {
for (const page of adminPages) {
if (window.authorizer.hasAccess(page, 2)) {
m.route.set(`/admin/${page}`);
return null;
}
}
return null;
}
示例3: setTimeout
setTimeout(() => {
m.route.set("/b");
setTimeout(() => {
console.assert(m.route.get() === "/b");
}, FRAME_BUDGET);
}, FRAME_BUDGET);
示例4: view
// http://mithril.js.org/route.html#wrapping-a-layout-component
////////////////////////////////////////////////////////////////////////////////
{
const Home = {
view() {
return "Welcome";
}
};
const state = {
term: "",
search() {
// save the state for this route
// this is equivalent to `history.replaceState({term: state.term}, null, location.href)`
m.route.set(m.route.get(), null, { replace: true, state: { term: state.term } });
// navigate away
location.href = "https://google.com/?q=" + state.term;
}
};
const Form: m.Comp<{term: string}, {}> = {
oninit(vnode) {
state.term = vnode.attrs.term || ""; // populated from the `history.state` property if the user presses the back button
},
view() {
return m("form", [
m("input[placeholder='Search']", { oninput: m.withAttr("value", v => { state.term = v; }), value: state.term }),
m("button", { onclick: state.search }, "Search")
]);