Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Ember.js Routes and Templates Customizing URLs

Getting rid of the '#' for the other routes

In my 'router.js' file of my Ember application, I wrote

Blogger.Router.map(function () {
  this.resource('posts', {path:'/'});
});

And that means that 'posts' lives on the root of the server...

But if I change the next route to:

this.resource('about', {path:'/about'});

I still get the '#'.

I.e., the URL when I click on 'about' is : http://0.0.0.0:8000/#/about

Just confused as to why I can't get rid of that silly '#' for the other paths.

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

D;

According to the Ember docs on routing and specifying the URL type:

By default the Router uses the browser's hash to load the starting state of your application and will keep it in sync as you move around. At present, this relies on a hashchange event existing in the browser.

There is an explanation on that same page as to how to change /#/posts/new to /posts/new.

Hope it helps,

Ken

Thank you Ken! So it took a little bit of testing to figure out, but essentially the solution for me was to add:

Blogger.Router.reopen({
  location: 'history'
});

To the top of my router.js file. And keeping the map functions below.

Now the # is gone! :)

The # is gone, but it sure doesn't seem to like it when you reload the page from a linked page like /contact/phone.

Rick

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

D;

Pleased to hear it worked out! Ember.js is a great framework with a lot of learning involved to access it's fullest potential. Sounds like you are on your way!

Happy coding,

Ken