简体   繁体   中英

Ember route not displaying template content

I am new to Ember and JS, so far the most extensive tutorials I found were using 1.0.0 pre2, but on the official site there is a very nice description and some examples of 1.0.0 pre4. I started to use that. I am stuck at routing, here is my code:

index.html

<body>
        Loaded.
        <script type="text/x-handlebars" data-template-name="application">
            In template displaying val: {{name}}

            {{#linkTo "index"}}<img class="logo">{{/linkTo}}

            <nav>
              {{#linkTo "about"}}About{{/linkTo}}
              {{#linkTo "favorites"}}Favorites{{/linkTo}}
            </nav>

        </script>

        <script type="text/x-handlebars" data-template-name="about">
            Here comes the about text: {{str}}
        </script>
</body>

app.js

window.App = Ember.Application.create();

App.ApplicationView = Ember.View.extend({
templateName: 'application'
})

App.ApplicationController = Ember.Controller.extend({
name: 'test'
})

App.AboutView = Ember.View.extend({
templateName: 'about'
})

App.AboutController = Ember.Controller.extend({
str: 'my string'
})


App.Router.map(function() {
 this.route("about", { path: "/about" });
 this.route("favorites", { path: "/favs" });
});

It's almost identical to the one from the site. What I want and think should happen, is that it will display the content of about template, but instead it just updates the url's to /#/about or /#/favs . What am I missing here?

What I want and think should happen, is that it will display the content of about template, but instead it just updates the url's to /#/about or /#/favs . What am I missing here?

Your application template does not have an {{outlet}} . With that in place it will work as expected.

See this jsbin for a working example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM