Skip to content

Instantly share code, notes, and snippets.

@pixelhandler
Created February 5, 2014 19:43
Show Gist options
  • Select an option

  • Save pixelhandler/8831498 to your computer and use it in GitHub Desktop.

Select an option

Save pixelhandler/8831498 to your computer and use it in GitHub Desktop.
Routing with a rootUrl, attempting to reproduce bug in double rootUrl. To use place the files in a folder named 'blog' then start a server in the parent (of blog) directory. `python -m SimpleHTTPServer` [ see http://pixelhandler.github.io/ember-data-extensions/blog/ ]
App = Ember.Application.create();
App.Router.reopen({
location: 'history',
rootURL: '/blog/'
});
App.Router.map(function() {
this.resource('posts', function () {
this.route('archive');
});
});
//App.ApplicationRoute = Ember.Router.extend({});
App.IndexRoute = Ember.Route.extend({
redirect: function () {
this.transitionTo('posts.index');
}
});
App.PostsIndexRoute = Ember.Route.extend({
// Non async model resolution (loaded) works as expected, url is /blog/posts
model: function () {
return ['red', 'yellow', 'blue'];
},
actions: {
home: function () {
this.transitionTo('posts.index');
}
}
});
App.PostsArchiveRoute = Ember.Route.extend({
model: function () {
// BUG, async resolution causes double rootURL /blog/blog/posts/archive
return new Ember.RSVP.Promise(function(resolve, reject) {
Ember.run.later(this, function () {
resolve(['green', 'purple', 'orange']);
// no reject(error);
}, 1000);
});
},
actions: {
home: function () {
this.transitionTo('posts.index');
}
}
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<script type="text/x-handlebars">
<h2> Welcome to Ember.js</h2>
{{outlet}}
</script>
<script type="text/x-handlebars" id="posts/index">
<h3>Posts</h3>
<a {{action 'home'}}>Home</a>
<ul>
{{#each item in model}}
<li>{{item}}</li>
{{/each}}
</ul>
{{#link-to 'posts.archive'}}Posts Archive{{/link-to}}
</script>
<script type="text/x-handlebars" id="posts/archive">
<h3>Archive</h3>
<a {{action 'home'}}>Home</a>
<ul>
{{#each item in model}}
<li>{{item}}</li>
{{/each}}
</ul>
{{#link-to 'posts.index'}}Posts Index{{/link-to}}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.2.1.js"></script>
<script src="http://builds.emberjs.com/canary/ember.js"></script>
<script src="./app.js"></script>
</body>
</html>
a {
cursor: pointer;
text-decoration: underline;
}
@pixelhandler
Copy link
Copy Markdown
Author

See bug at : emberjs/ember.js#1244

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment