UNPKG

react-crossroads

Version:

Client side router for web applications built with React and utilizing the Flux architecture. The backing routing engine is CrossroadsJs.

58 lines (49 loc) 1.42 kB
var ExecutionEnvironment, RefreshLocation, getWindowPath, invariant, join, _initialPath, _initialPathRgx; invariant = require('react/lib/invariant'); getWindowPath = require('./getWindowPath'); ExecutionEnvironment = require('react/lib/ExecutionEnvironment'); join = require('path').join; _initialPath = null; _initialPathRgx = null; RefreshLocation = { setup: function(onChange, initialPath) { invariant(ExecutionEnvironment.canUseDOM, 'You cannot use RefreshLocation in an environment with no DOM'); _initialPath = initialPath || ''; return _initialPathRgx = new RegExp("^" + (initialPath || '')); }, push: function(path) { path = join(_initialPath, path); return window.location = path; }, replace: function(path) { path = join(_initialPath, path); return window.location.replace(path); }, pop: function() { return window.history.back(); }, getCurrentPath: function() { var path; path = getWindowPath(); path = path.replace(_initialPathRgx, ''); if (path === '') { return '/'; } else { return path; } }, isSupportedOrFallback: function() { if (ExecutionEnvironment.canUseDOM) { return true; } else { return 'memory'; } }, pathToHref: function(path) { return join(_initialPath, path); }, toString: function() { return '<RefreshLocation>'; } }; module.exports = RefreshLocation;