Lookup route from URL in Ember router - ember.js

The Ember router creates a URL from a route, e.g. with the link-to helper. Is it possible to reverse-lookup a route from a given URL?
The reason for this is that I have some absolute URL links in my database which point to pages in my Ember app, and I want to transition to them within the app. Using <a href={{link}}> works, but breaks my tests (when running ember test -s) as following the link redirects the whole browser page, stopping the test suite. If it's possible to redirect to an absolute URL without breaking the test suite that would also do the trick.

Related

Why should I use {{#link-to}} instead of <a></a> in EmberJS?

This is a pretty newbie question. However, in EmberJS, I've found that both of the methods work for linking to the blog page in my application.
<p>{{#link-to 'posts'}} See my blog{{/link-to}}</p>
See my blog
Is it better to use {{link-to}} in EmberJS? How come?
The difference is that the {{link-to}} component will navigate to the specified route within the current running Ember application, while <a href="posts"> will do a new browser request to that location and re-start your Ember app at that route. You should use {{link-to}} since you'll be using the Ember internals to navigate within your single-page application and it will be a smoother user experience.
While they both can work, watch your browser closely and you'll see the anchor tag will give you a page refresh and re-launch your Ember app (though in the right location). Using a {{link-to}} will feel faster since Ember is presenting the new page via javascript rather than restarting after a page refresh. It's the difference between navigating within a single-page application, and jumping into a SPA from an external page.
While Ember does render an anchor tag in place of the {{link-to}} at run-time, it interjects to stop the default anchor tag behaviour. The docs explain it like so:
By default the {{link-to}} component prevents the default browser
action by calling preventDefault() as this sort of action bubbling is
normally handled internally and we do not want to take the browser to
a new URL (for example).
(from https://emberjs.com/api/classes/Ember.Templates.helpers.html#toc_allowing-default-action)
Also, with the {{link-to}} component you can pass a model directly into the route. This is a bit more advanced, but the Ember guides have some good examples.
https://guides.emberjs.com/v2.13.0/templates/links/

Ember-cli build issue: only able to navigate to index and other routes not working

once building the ember app using ember build -prod, and viewing the app, I only get the index and whenever I try to access another route for example /about I get a 404, same with all of the other routes. All routes work when you serve with the cli.
Below is the current source
https://gitlab.com/remon/ember/tree/master

Backbone.js with Rails routing

I have backbone view that navigates url to localhost:3000/about but when i do realod page, Rails routing takes care of routing and redirects me to rails page, not Backbone view. I was reading some tutorials about backbone routing, for example: http://www.codeproject.com/Articles/803073/BackBone-Tutorial-Part-Understanding-Backbone-js-R but anything i do, it doesn't work. Is it even possible to route page after reload to correct backbone view, as it is easy for Rails?
It is normal. When the route is hit, your backend router will fetch and return the corresponding rails view if the router is configured to do so.
When the page is loaded into the browser, only at this moment the backbone router should be instantiated.
By default, Backbone uses hashtags# to route, but by instantiating the router with pushstate:true, you can fetch templates from the backend without losing front end state in your application.

Replace, not append to, the site's body content in Ember.js

I had the following idea: my page at example.org serves classic HTML from the server. Besides, EmberJS is loaded, too, and waiting to come into action:
as soon as somebody hits an ember route then, for example example.org/#/login, the current should be replaced by what the view renders for it. From then, the whole app should serve as one-page-app.
Is that a good idea? Anyway, I don't know how to get that started. Overriding View's appendTo method or setting the rootElement property as in http://emberjs.com/guides/configuring-ember/embedding-applications/ does not suffice because if that were the body, the view output is just appended thereā€¦
If your entire Ember application requires a user to be logged in, it is valid to have two separate "apps":
A regular non single-page application (server-side using rails, PHP or C#) with a sign up and login pages
A single-page application (i.e. Ember) send as soon as the user hits the login button in your regular app
You will have 2 index.html pages, one for each application (and it's okay to do that!). The URL of the Ember App could be under example.org/app/.... You will need to configure the router of the regular application to server your Ember App for all URLs starting with /app/.
Does that help? :)

How to change hashbang url to history API

I'm using ember1.0-rc3, i want to change hashbang urls into normal url format (ie, www.site.com/admin#/page1 to www.site.com/admin/page1).In order to make this change,i use location: "history" in app router.
But when i reload a page or bookmark a page doesn't works, it redirects to home page only.I want the options reload and bookmark in my app, without changing redirect urls in .htaccess file.Is there any way for it?Thanks in advance
In order to use HTML5 history with a single page app like ember, your server must be have the behavior of rendering your main index.html file for any URL. The Ember router has the logic to look at the URL when it loads and go to the correct route.