Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseURL other than / makes troubles #19

Open
tschoartschi opened this issue Aug 11, 2015 · 13 comments
Open

BaseURL other than / makes troubles #19

tschoartschi opened this issue Aug 11, 2015 · 13 comments
Labels

Comments

@tschoartschi
Copy link

@GavinJoyce we host our ember app in a subdirectory called /app, when I use Ember-Href-To the links does not work, because Ember-Href-To resolves the links to /app/app. We are using Ember-CLI and our environment.js looks as follows:

module.exports = function (environment) {
    var ENV = {
        environment: environment,
        baseURL: '/app/'
        // ...
        // ...
    }
    return ENV;
}

I solved it by making my own helper based on Ember-Href-To. The helper looks as follows:

import Ember from 'ember';
import { hrefTo } from 'ember-href-to/helpers/href-to';

export function hrefToX(params/*, hash*/) {
    var url = hrefTo(params);
    var baseURL = APPENV.baseURL.replace(/\/$/, ''); // APPENV is globally available... jeah this is a relict from our old code from ember-cli 0.0.39
    url = url.replace(baseURL, '');
    return url;
}

export default Ember.Helper.helper(hrefToX);

It works but if I hover the links built with hrefToX the links dont contain the /app/. This does not happen with link-to. Is my solution the right way to go or is there a better way to do it?

Thanks a lot

@GavinJoyce
Copy link
Contributor

We use the rootURL property on the Router, href-to is designed to work with this:

var Router = Ember.Router.extend({
  rootURL: '/a'
});

Perhaps one of these mechanisms is a legacy way of setting the root URL?

@tschoartschi
Copy link
Author

@GavinJoyce at first of all, thanks for your effort and ember-href-to.

I'm not sure if we are using a legacy way of setting the root URL. I just started a new ember-cli project yesterday (with ember cli version 1.13.13) and in the environment.js there is still an entry for baseURL. If I add the rootURL to the router I have to remove the baseURL from the environment.js, I'm not totally sure if this is fine or if I break something from ember-cli if I remove the baseURL from the environment.js. Do you have any insights on this?

@GavinJoyce
Copy link
Contributor

Perhaps you could create a simple ember twiddle which demonstrates the problem? This would allow me to make a suggestion or a fix much faster

@tschoartschi
Copy link
Author

@GavinJoyce okay, I'll try to figure it out how I can setup an Ember CLI project with an environment.js as an ember twiddle. At the first glance I didn't see how to do this. I'll check it out later in more depth.

@tschoartschi
Copy link
Author

I tried to reproduce the issue but it is not possible. Maybe I have to try harder. I'll let you know when I have a sample which reproduces the bug. In the meanwhile thanks a lot for your effort

@nanuxbe
Copy link

nanuxbe commented Dec 10, 2015

I can confirm that I have the same issue using baseURL.

I don't think baseURL is legacy as it is still the "official" way of ember-cli guides

rootURL doesn't seem to be part of the "Routing Introduction" section of Ember Guides since v2.0.0 though but might be somewhere else.

@nanuxbe
Copy link

nanuxbe commented Dec 10, 2015

I also have to add that this does only happen with sub-routes:

  • route 'blog' will resolve correctly to app/blog
  • route 'blog/detail' will resolve incorrectly to app/app/blog:detail

And finally {{link-to}} doesn't have the same problem (if it can be of any help)

I don't think it's possible to create an ember-cli twiddle for this but I'll try to find some time this weekend to create a small app which reproduces the problem

@GavinJoyce
Copy link
Contributor

Thanks, a sample application which demonstrates the problem will allow me to address the issue much more rapidly

@GavinJoyce GavinJoyce added the bug label Dec 10, 2015
@tschoartschi
Copy link
Author

@GavinJoyce: It was quite hard to reproduce the bug on a fresh ember-cli project. The problem arises when you add a fallback route to the router. What we have in our project is: this.route('error404', {path: '/*path'}); and this seems to cause problems in conjunction with setting a base url in environment.js.

I created a github repo because I don't know how to outline this problem in an ember-fiddle. Hope this is ok?

Basically you will see a simple ember-cli app which has 3 pages, index/home, about and contact. Then there is the navigation once with embers link-to helper, once with ember-href-to and once with the workaround which I posted when I opened the issue. But my workaround does not produce the same values for href as embers link-to. When you hover the links you will notice that the link-to links still have the base url in it and the links from my workaround does not.

Hope this helps finding the problem. I'm not quite sure if it is a bug with ember-href-to or if it is a problem how the router is used?

@GavinJoyce
Copy link
Contributor

@tschoartschi thanks for the repo.

I can see that the rendered URLs are correct:

image

It looks like _getNormalisedRootUrl will need to be updated to handle this case:
https://github.com/intercom/ember-href-to/blob/master/addon/helpers/href-to.js#L6

@tschoartschi
Copy link
Author

I cross-checked it and I think you are right. The _getNormalisedRootUrl seems to cause the troubles. Do you know how to solve it? I could assist you if you tell me the way to go 😉

@rwjblue
Copy link

rwjblue commented Apr 27, 2016

baseURL is going to die 🔥 🔥 🔥 🔥 🔥 🔥 . See ember-cli/ember-cli#5792 and a blog post we are working on in emberjs/website#2569.

@nathanhammond
Copy link

baseURL is dead as of 3.0. Nominate for closure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants