kadirahq / flow-router

Carefully Designed Client Side Router for Meteor
MIT License
1.09k stars 193 forks source link

Setting ROOT_URL with a path causes FlowRouter.url() to report incorrect url #684

Open carlevans719 opened 8 years ago

carlevans719 commented 8 years ago

If the ROOT_URL environment variable is set to contain a path (e.g. http://localhost:3000/app), FlowRouter.url() inserts an extra forward slash in the return value.

Repro: https://github.com/carlevans719/flow-router-root-url-repro

carlevans719 commented 8 years ago

Possibly related to 89fc983

carlevans719 commented 8 years ago

pathWithoutBase = pathWithoutBase.replace(/^\//, ''); on line 8 of lib/router.js resolves the issue

Serubin commented 7 years ago

I'm having a similar issue - I went through and added some logging to the FlowRouter.url() function and found this output:

  var completePath = this.path.apply(this, arguments);
  // /wekan/b
  var basePath = this._basePath || '/';
  // /wekan
  var pathWithoutBase = completePath.replace(new RegExp('^' + basePath), '');
  // /b
  return Meteor.absoluteUrl(pathWithoutBase);
  // https://mydomain.net/wekan//b

The router should definitely be taking out the leading slash.

Changing line 7 of lib/router.js to

var pathWithoutBase = completePath.replace(new RegExp('^(\/)|' + basePath), '');

An argument could be added for keeping that leading slash if necessary (ie. using a hashbang).

sunhaolin commented 7 years ago

@Serubin

var completePath = '/wekan/b';
var basePath = '/wekan';
var pathWithoutBase = completePath.replace(new RegExp('^(\/)|' + basePath), '');
Meteor.absoluteUrl(pathWithoutBase);
// "http://192.168.0.21/wekan/wekan/b"
Serubin commented 7 years ago

@sunhaolin Ah, yes. Good catch, thank you.

This should fix it and account for the slash immediately following the base path if it exists.

var pathWithoutBase = completePath.replace(new RegExp('^' + basePath + '(\/)'), '');