page.js 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. const url = require('url');
  3. const path = require('path');
  4. const pkgfile = require('../../package');
  5. const routerSeparator = '#!';
  6. let parseLocationFromFullUrl = function (fullUrl) {
  7. if (!fullUrl || fullUrl.indexOf(routerSeparator) < 0) {
  8. return '';
  9. }
  10. const separatorIndex = fullUrl.indexOf(routerSeparator);
  11. if (fullUrl.length <= separatorIndex + routerSeparator.length) {
  12. return '';
  13. }
  14. return fullUrl.substring(fullUrl.indexOf(routerSeparator) + routerSeparator.length);
  15. };
  16. let getIndexUrl = function () {
  17. return url.format({
  18. protocol: 'file',
  19. slashes: true,
  20. pathname: path.join(__dirname, '../../', pkgfile.entry)
  21. });
  22. };
  23. let getPageFullUrl = function (location) {
  24. if (!location) {
  25. return getIndexUrl();
  26. }
  27. return getIndexUrl() + routerSeparator + location;
  28. };
  29. module.exports = {
  30. parseLocationFromFullUrl: parseLocationFromFullUrl,
  31. getPageFullUrl: getPageFullUrl
  32. }