history#createLocation JavaScript Examples
The following examples show how to use
history#createLocation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StaticRouter.js From Learning-Redux with MIT License | 6 votes |
render() {
const { basename = "", context = {}, location = "/", ...rest } = this.props;
const history = {
createHref: path => addLeadingSlash(basename + createURL(path)),
action: "POP",
location: stripBasename(basename, createLocation(location)),
push: this.handlePush,
replace: this.handleReplace,
go: staticHandler("go"),
goBack: staticHandler("goBack"),
goForward: staticHandler("goForward"),
listen: this.handleListen,
block: this.handleBlock
};
return <Router {...rest} history={history} staticContext={context} />;
}
Example #2
Source File: StaticRouter.js From spring-boot-ecommerce with Apache License 2.0 | 6 votes |
render() {
const { basename = "", context = {}, location = "/", ...rest } = this.props;
const history = {
createHref: path => addLeadingSlash(basename + createURL(path)),
action: "POP",
location: stripBasename(basename, createLocation(location)),
push: this.handlePush,
replace: this.handleReplace,
go: staticHandler("go"),
goBack: staticHandler("goBack"),
goForward: staticHandler("goForward"),
listen: this.handleListen,
block: this.handleBlock
};
return <Router {...rest} history={history} staticContext={context} />;
}
Example #3
Source File: react-router.js From spring-boot-ecommerce with Apache License 2.0 | 5 votes |
/**
* The public API for navigating programmatically with a component.
*/
function Redirect(_ref) {
var computedMatch = _ref.computedMatch,
to = _ref.to,
_ref$push = _ref.push,
push = _ref$push === void 0 ? false : _ref$push;
return React.createElement(context.Consumer, null, function (context) {
!context ? process.env.NODE_ENV !== "production" ? invariant(false, "You should not use <Redirect> outside a <Router>") : invariant(false) : void 0;
var history = context.history,
staticContext = context.staticContext;
var method = push ? history.push : history.replace;
var location = createLocation(computedMatch ? typeof to === "string" ? generatePath(to, computedMatch.params) : _extends({}, to, {
pathname: generatePath(to.pathname, computedMatch.params)
}) : to); // When rendering in a static context,
// set the new location immediately.
if (staticContext) {
method(location);
return null;
}
return React.createElement(Lifecycle, {
onMount: function onMount() {
method(location);
},
onUpdate: function onUpdate(self, prevProps) {
var prevLocation = createLocation(prevProps.to);
if (!locationsAreEqual(prevLocation, _extends({}, location, {
key: prevLocation.key
}))) {
method(location);
}
},
to: to
});
});
}
Example #4
Source File: Link.js From Lynx with MIT License | 5 votes |
Link = function (_React$Component) {
_inherits(Link, _React$Component);
function Link() {
var _temp, _this, _ret;
_classCallCheck(this, Link);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.handleClick = function (event) {
if (_this.props.onClick) _this.props.onClick(event);
if (!event.defaultPrevented && // onClick prevented default
event.button === 0 && // ignore everything but left clicks
!_this.props.target && // let browser handle "target=_blank" etc.
!isModifiedEvent(event) // ignore clicks with modifier keys
) {
event.preventDefault();
var history = _this.context.router.history;
var _this$props = _this.props,
replace = _this$props.replace,
to = _this$props.to;
if (replace) {
history.replace(to);
} else {
history.push(to);
}
}
}, _temp), _possibleConstructorReturn(_this, _ret);
}
Link.prototype.render = function render() {
var _props = this.props,
replace = _props.replace,
to = _props.to,
innerRef = _props.innerRef,
props = _objectWithoutProperties(_props, ["replace", "to", "innerRef"]); // eslint-disable-line no-unused-vars
invariant(this.context.router, "You should not use <Link> outside a <Router>");
invariant(to !== undefined, 'You must specify the "to" property');
var history = this.context.router.history;
var location = typeof to === "string" ? createLocation(to, null, null, history.location) : to;
var href = history.createHref(location);
return React.createElement("a", _extends({}, props, { onClick: this.handleClick, href: href, ref: innerRef }));
};
return Link;
}(React.Component)
Example #5
Source File: StaticRouter.js From Lynx with MIT License | 5 votes |
StaticRouter = function (_React$Component) {
_inherits(StaticRouter, _React$Component);
function StaticRouter() {
var _temp, _this, _ret;
_classCallCheck(this, StaticRouter);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.createHref = function (path) {
return addLeadingSlash(_this.props.basename + createURL(path));
}, _this.handlePush = function (location) {
var _this$props = _this.props,
basename = _this$props.basename,
context = _this$props.context;
context.action = "PUSH";
context.location = addBasename(basename, createLocation(location));
context.url = createURL(context.location);
}, _this.handleReplace = function (location) {
var _this$props2 = _this.props,
basename = _this$props2.basename,
context = _this$props2.context;
context.action = "REPLACE";
context.location = addBasename(basename, createLocation(location));
context.url = createURL(context.location);
}, _this.handleListen = function () {
return noop;
}, _this.handleBlock = function () {
return noop;
}, _temp), _possibleConstructorReturn(_this, _ret);
}
StaticRouter.prototype.getChildContext = function getChildContext() {
return {
router: {
staticContext: this.props.context
}
};
};
StaticRouter.prototype.componentWillMount = function componentWillMount() {
warning(!this.props.history, "<StaticRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { StaticRouter as Router }`.");
};
StaticRouter.prototype.render = function render() {
var _props = this.props,
basename = _props.basename,
context = _props.context,
location = _props.location,
props = _objectWithoutProperties(_props, ["basename", "context", "location"]);
var history = {
createHref: this.createHref,
action: "POP",
location: stripBasename(basename, createLocation(location)),
push: this.handlePush,
replace: this.handleReplace,
go: staticHandler("go"),
goBack: staticHandler("goBack"),
goForward: staticHandler("goForward"),
listen: this.handleListen,
block: this.handleBlock
};
return React.createElement(Router, _extends({}, props, { history: history }));
};
return StaticRouter;
}(React.Component)
Example #6
Source File: Redirect.js From Lynx with MIT License | 5 votes |
Redirect = function (_React$Component) {
_inherits(Redirect, _React$Component);
function Redirect() {
_classCallCheck(this, Redirect);
return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
}
Redirect.prototype.isStatic = function isStatic() {
return this.context.router && this.context.router.staticContext;
};
Redirect.prototype.componentWillMount = function componentWillMount() {
invariant(this.context.router, "You should not use <Redirect> outside a <Router>");
if (this.isStatic()) this.perform();
};
Redirect.prototype.componentDidMount = function componentDidMount() {
if (!this.isStatic()) this.perform();
};
Redirect.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
var prevTo = createLocation(prevProps.to);
var nextTo = createLocation(this.props.to);
if (locationsAreEqual(prevTo, nextTo)) {
warning(false, "You tried to redirect to the same route you're currently on: " + ("\"" + nextTo.pathname + nextTo.search + "\""));
return;
}
this.perform();
};
Redirect.prototype.computeTo = function computeTo(_ref) {
var computedMatch = _ref.computedMatch,
to = _ref.to;
if (computedMatch) {
if (typeof to === "string") {
return generatePath(to, computedMatch.params);
} else {
return _extends({}, to, {
pathname: generatePath(to.pathname, computedMatch.params)
});
}
}
return to;
};
Redirect.prototype.perform = function perform() {
var history = this.context.router.history;
var push = this.props.push;
var to = this.computeTo(this.props);
if (push) {
history.push(to);
} else {
history.replace(to);
}
};
Redirect.prototype.render = function render() {
return null;
};
return Redirect;
}(React.Component)
Example #7
Source File: react-router-dom.js From spring-boot-ecommerce with Apache License 2.0 | 5 votes |
normalizeToLocation = function normalizeToLocation(to, currentLocation) {
return typeof to === "string" ? createLocation(to, null, null, currentLocation) : to;
}
Example #8
Source File: StaticRouter.js From spring-boot-ecommerce with Apache License 2.0 | 5 votes |
navigateTo(location, action) {
const { basename = "", context = {} } = this.props;
context.action = action;
context.location = addBasename(basename, createLocation(location));
context.url = createURL(context.location);
}
Example #9
Source File: Redirect.js From spring-boot-ecommerce with Apache License 2.0 | 5 votes |
/**
* The public API for navigating programmatically with a component.
*/
function Redirect({ computedMatch, to, push = false }) {
return (
<RouterContext.Consumer>
{context => {
invariant(context, "You should not use <Redirect> outside a <Router>");
const { history, staticContext } = context;
const method = push ? history.push : history.replace;
const location = createLocation(
computedMatch
? typeof to === "string"
? generatePath(to, computedMatch.params)
: {
...to,
pathname: generatePath(to.pathname, computedMatch.params)
}
: to
);
// When rendering in a static context,
// set the new location immediately.
if (staticContext) {
method(location);
return null;
}
return (
<Lifecycle
onMount={() => {
method(location);
}}
onUpdate={(self, prevProps) => {
const prevLocation = createLocation(prevProps.to);
if (
!locationsAreEqual(prevLocation, {
...location,
key: prevLocation.key
})
) {
method(location);
}
}}
to={to}
/>
);
}}
</RouterContext.Consumer>
);
}
Example #10
Source File: react-router.js From spring-boot-ecommerce with Apache License 2.0 | 5 votes |
StaticRouter =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(StaticRouter, _React$Component);
function StaticRouter() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
_this.handlePush = function (location) {
return _this.navigateTo(location, "PUSH");
};
_this.handleReplace = function (location) {
return _this.navigateTo(location, "REPLACE");
};
_this.handleListen = function () {
return noop;
};
_this.handleBlock = function () {
return noop;
};
return _this;
}
var _proto = StaticRouter.prototype;
_proto.navigateTo = function navigateTo(location, action) {
var _this$props = this.props,
_this$props$basename = _this$props.basename,
basename = _this$props$basename === void 0 ? "" : _this$props$basename,
_this$props$context = _this$props.context,
context = _this$props$context === void 0 ? {} : _this$props$context;
context.action = action;
context.location = addBasename(basename, createLocation(location));
context.url = createURL(context.location);
};
_proto.render = function render() {
var _this$props2 = this.props,
_this$props2$basename = _this$props2.basename,
basename = _this$props2$basename === void 0 ? "" : _this$props2$basename,
_this$props2$context = _this$props2.context,
context = _this$props2$context === void 0 ? {} : _this$props2$context,
_this$props2$location = _this$props2.location,
location = _this$props2$location === void 0 ? "/" : _this$props2$location,
rest = _objectWithoutPropertiesLoose(_this$props2, ["basename", "context", "location"]);
var history = {
createHref: function createHref(path) {
return addLeadingSlash(basename + createURL(path));
},
action: "POP",
location: stripBasename(basename, createLocation(location)),
push: this.handlePush,
replace: this.handleReplace,
go: staticHandler("go"),
goBack: staticHandler("goBack"),
goForward: staticHandler("goForward"),
listen: this.handleListen,
block: this.handleBlock
};
return React.createElement(Router, _extends({}, rest, {
history: history,
staticContext: context
}));
};
return StaticRouter;
}(React.Component)
Example #11
Source File: locationUtils.js From Learning-Redux with MIT License | 5 votes |
normalizeToLocation = (to, currentLocation) => {
return typeof to === "string"
? createLocation(to, null, null, currentLocation)
: to;
}
Example #12
Source File: react-router-dom.js From Learning-Redux with MIT License | 5 votes |
normalizeToLocation = function normalizeToLocation(to, currentLocation) {
return typeof to === "string" ? createLocation(to, null, null, currentLocation) : to;
}
Example #13
Source File: StaticRouter.js From Learning-Redux with MIT License | 5 votes |
navigateTo(location, action) {
const { basename = "", context = {} } = this.props;
context.action = action;
context.location = addBasename(basename, createLocation(location));
context.url = createURL(context.location);
}
Example #14
Source File: Redirect.js From Learning-Redux with MIT License | 5 votes |
/**
* The public API for navigating programmatically with a component.
*/
function Redirect({ computedMatch, to, push = false }) {
return (
<RouterContext.Consumer>
{context => {
invariant(context, "You should not use <Redirect> outside a <Router>");
const { history, staticContext } = context;
const method = push ? history.push : history.replace;
const location = createLocation(
computedMatch
? typeof to === "string"
? generatePath(to, computedMatch.params)
: {
...to,
pathname: generatePath(to.pathname, computedMatch.params)
}
: to
);
// When rendering in a static context,
// set the new location immediately.
if (staticContext) {
method(location);
return null;
}
return (
<Lifecycle
onMount={() => {
method(location);
}}
onUpdate={(self, prevProps) => {
const prevLocation = createLocation(prevProps.to);
if (
!locationsAreEqual(prevLocation, {
...location,
key: prevLocation.key
})
) {
method(location);
}
}}
to={to}
/>
);
}}
</RouterContext.Consumer>
);
}
Example #15
Source File: react-router.js From Learning-Redux with MIT License | 5 votes |
StaticRouter =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(StaticRouter, _React$Component);
function StaticRouter() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
_this.handlePush = function (location) {
return _this.navigateTo(location, "PUSH");
};
_this.handleReplace = function (location) {
return _this.navigateTo(location, "REPLACE");
};
_this.handleListen = function () {
return noop;
};
_this.handleBlock = function () {
return noop;
};
return _this;
}
var _proto = StaticRouter.prototype;
_proto.navigateTo = function navigateTo(location, action) {
var _this$props = this.props,
_this$props$basename = _this$props.basename,
basename = _this$props$basename === void 0 ? "" : _this$props$basename,
_this$props$context = _this$props.context,
context = _this$props$context === void 0 ? {} : _this$props$context;
context.action = action;
context.location = addBasename(basename, createLocation(location));
context.url = createURL(context.location);
};
_proto.render = function render() {
var _this$props2 = this.props,
_this$props2$basename = _this$props2.basename,
basename = _this$props2$basename === void 0 ? "" : _this$props2$basename,
_this$props2$context = _this$props2.context,
context = _this$props2$context === void 0 ? {} : _this$props2$context,
_this$props2$location = _this$props2.location,
location = _this$props2$location === void 0 ? "/" : _this$props2$location,
rest = _objectWithoutPropertiesLoose(_this$props2, ["basename", "context", "location"]);
var history = {
createHref: function createHref(path) {
return addLeadingSlash(basename + createURL(path));
},
action: "POP",
location: stripBasename(basename, createLocation(location)),
push: this.handlePush,
replace: this.handleReplace,
go: staticHandler("go"),
goBack: staticHandler("goBack"),
goForward: staticHandler("goForward"),
listen: this.handleListen,
block: this.handleBlock
};
return React.createElement(Router, _extends({}, rest, {
history: history,
staticContext: context
}));
};
return StaticRouter;
}(React.Component)
Example #16
Source File: react-router.js From Learning-Redux with MIT License | 5 votes |
/**
* The public API for navigating programmatically with a component.
*/
function Redirect(_ref) {
var computedMatch = _ref.computedMatch,
to = _ref.to,
_ref$push = _ref.push,
push = _ref$push === void 0 ? false : _ref$push;
return React.createElement(context.Consumer, null, function (context) {
!context ? process.env.NODE_ENV !== "production" ? invariant(false, "You should not use <Redirect> outside a <Router>") : invariant(false) : void 0;
var history = context.history,
staticContext = context.staticContext;
var method = push ? history.push : history.replace;
var location = createLocation(computedMatch ? typeof to === "string" ? generatePath(to, computedMatch.params) : _extends({}, to, {
pathname: generatePath(to.pathname, computedMatch.params)
}) : to); // When rendering in a static context,
// set the new location immediately.
if (staticContext) {
method(location);
return null;
}
return React.createElement(Lifecycle, {
onMount: function onMount() {
method(location);
},
onUpdate: function onUpdate(self, prevProps) {
var prevLocation = createLocation(prevProps.to);
if (!locationsAreEqual(prevLocation, _extends({}, location, {
key: prevLocation.key
}))) {
method(location);
}
},
to: to
});
});
}
Example #17
Source File: Modals.js From actual with MIT License | 4 votes |
function Modals({
history,
modalStack,
isHidden,
accounts,
categoryGroups,
categories,
payees,
budgetId,
actions
}) {
return modalStack.map(({ name, options = {} }, idx) => {
const modalProps = {
onClose: actions.popModal,
onBack: actions.popModal,
showBack: idx > 0,
isCurrent: idx === modalStack.length - 1,
isHidden,
stackIndex: idx
};
let location = createLocation('/' + name);
return (
<Switch key={name} location={location}>
<Route path="/import-transactions">
<ImportTransactions modalProps={modalProps} options={options} />
</Route>
<Route path="/add-account">
<CreateAccount modalProps={modalProps} actions={actions} />
</Route>
<Route path="/add-local-account">
<CreateLocalAccount
modalProps={modalProps}
actions={actions}
history={history}
/>
</Route>
<Route path="/close-account">
<CloseAccount
modalProps={modalProps}
account={options.account}
balance={options.balance}
canDelete={options.canDelete}
accounts={accounts.filter(acct => acct.closed === 0)}
categoryGroups={categoryGroups}
actions={actions}
/>
</Route>
<Route path="/select-linked-accounts">
<SelectLinkedAccounts
modalProps={modalProps}
institution={options.institution}
publicToken={options.publicToken}
accounts={options.accounts}
upgradingId={options.upgradingId}
actions={actions}
/>
</Route>
<Route path="/configure-linked-accounts">
<ConfigureLinkedAccounts
modalProps={modalProps}
institution={options.institution}
publicToken={options.publicToken}
accounts={options.accounts}
upgradingId={options.upgradingId}
actions={actions}
/>
</Route>
<Route
path="/confirm-category-delete"
render={() => {
const { category, group, onDelete } = options;
return (
<ConfirmCategoryDelete
modalProps={modalProps}
actions={actions}
category={categories.find(c => c.id === category)}
group={categoryGroups.find(g => g.id === group)}
categoryGroups={categoryGroups}
onDelete={onDelete}
/>
);
}}
/>
<Route
path="/load-backup"
render={() => {
return (
<Component
initialState={{ backups: [] }}
didMount={async ({ setState }) => {
setState({
backups: await send('backups-get', { id: budgetId })
});
listen('backups-updated', backups => {
setState({ backups });
});
}}
willUnmount={() => {
unlisten('backups-updated');
}}
>
{({ state }) => (
<LoadBackup
budgetId={budgetId}
modalProps={modalProps}
actions={actions}
backups={state.backups}
/>
)}
</Component>
);
}}
/>
<Route
path="/manage-payees"
render={() => {
return (
<ManagePayeesWithData
history={history}
modalProps={modalProps}
initialSelectedIds={
options.selectedPayee ? [options.selectedPayee] : undefined
}
/>
);
}}
/>
<Route
path="/manage-rules"
render={() => {
return (
<ManageRules
history={history}
modalProps={modalProps}
payeeId={options.payeeId}
/>
);
}}
/>
<Route
path="/edit-rule"
render={() => {
return (
<EditRule
history={history}
modalProps={modalProps}
defaultRule={options.rule}
onSave={options.onSave}
/>
);
}}
/>
<Route
path="/merge-unused-payees"
render={() => {
return (
<MergeUnusedPayees
history={history}
modalProps={modalProps}
payeeIds={options.payeeIds}
targetPayeeId={options.targetPayeeId}
/>
);
}}
/>
<Route
path="/plaid-external-msg"
render={() => {
return (
<PlaidExternalMsg
modalProps={modalProps}
actions={actions}
onMoveExternal={options.onMoveExternal}
onClose={() => {
options.onClose && options.onClose();
send('poll-web-token-stop');
}}
onSuccess={options.onSuccess}
/>
);
}}
/>
<Route
path="/create-encryption-key"
render={() => {
return (
<CreateEncryptionKey
key={name}
modalProps={modalProps}
actions={actions}
options={options}
/>
);
}}
/>
<Route
path="/fix-encryption-key"
render={() => {
return (
<FixEncryptionKey
key={name}
modalProps={modalProps}
actions={actions}
options={options}
/>
);
}}
/>
<Route
path="/edit-field"
render={() => {
return (
<EditField
key={name}
modalProps={modalProps}
actions={actions}
name={options.name}
onSubmit={options.onSubmit}
/>
);
}}
/>
<Route path="/welcome-screen">
<WelcomeScreen modalProps={modalProps} actions={actions} />
</Route>
</Switch>
);
});
}