Closed AhmadMayo closed 6 years ago
How about this?
import UniversalRouter from 'universal-router';
import generateUrls from 'universal-router/generateUrls';
const router = new UniversalRouter({ name: 'home', path: '/home' });
const path = generateUrls(router);
const url = (...args) => `https://www.example.com${path(...args)}`;
path('home'); // => /home
url('home'); // => https://www.example.com/home
Playground: http://jsfiddle.net/frenzzy/jwcbme5x/
already thought of that, but having development server in local machine, staging server and a production server makes it's hard to hard code the origin
Then you can use environment variables in your server-side code instead of hard coded values or use current host aka req.get('host')
.
On client side you can use the origin which was returned from backend side or window.location.origin
Thinking about it, as universal router is "universal" it should not contain logic related to the browser. thanks for your time, I'm gona close the issue, and try to figure out the solution
Great idea. Also I can solve the problem from the history package I'm using, that sounds more appropriate. where's the "close issue" button? :smile: . Please close the issue.
Is their a way to get the full url? I define the route like this '/home' but Sometimes I want to generate the route line this 'www.myawesomeapp.com/home'