Can I use require(“path”).join to safely concatenate urls?

前端 未结 15 529
臣服心动
臣服心动 2020-12-23 13:06

Is this safe to use require(\"path\").join to concatenate URLs, for example:

require(\"path\").join(\"http://example.com\", \"ok\"); 
//returns          


        
15条回答
  •  时光取名叫无心
    2020-12-23 13:45

    If you use Angular, you can use Location:

    import { Location } from '@angular/common';
    // ...
    Location.joinWithSlash('beginning', 'end');
    

    Works only on 2 arguments though, so you have to chain calls or write a helper function to do that if needed.

提交回复
热议问题