首页 文章

路由角度2:没有出现

提问于
浏览
0

我正在尝试使用Angular2实现基本路由,但没有成功:-D实际上,我甚至没有错误,我只是在页面上什么都没有(这对我没有帮助调试问题^^) . 这是我做的:

  • 来自'angular / router'的Bootstrap“ROUTER_PROVIDERS”

  • 定义主要组件中的路线(见下文) .

  • 在主要组件的模板中添加“router-outlet”元素 .

  • 主要组件实现“ngOnInit " and uses the router to redirect the user to the route named " Company” .

路线:

@RouteConfig([
    { path: '/company', component: CompanyComponent, name: 'Company' },
    { path: '/missions', component: MissionComponent, name: 'Mission' }
])

当我访问我的页面时,我被正确地重定向到主组件模板中的“/ company ", so it looks like the routes are correctly defined, but still, I don't see anything. I tried to add the " company”元素以查看该组件是否正常,当我这样做时,它显示正确,所以我不知道组件相关的问题 .

我从角度教程检查了实例,我看到的唯一区别是它们使用“路径" decorator instead of " RouteConfig ". When I do that, WebStorm only found "路线" in " angular2 / alt_router”并且它无论如何都不起作用(我有一个错误,说Angular找不到我的路线).. .

看起来好像没有找到/填满“路由器插座”,但我不明白为什么 .

我正在使用angular2 beta 17

1 回答

  • 1

    您正在阅读的文档与您使用的代码之间的差异是角度版本 . 如果你去Angular2 Routing & Navigation link的网站,你可以看到粗体显示:

    This chapter is a work in progress.
    
    It describes the release candidate Component Router which replaces the beta router.
    

    您使用的版本是旧版本,可以找到文档here

    在那里,您可以查看示例应用,看看与您的实现有何不同 .

    但是我建议你升级到angular2的RC版本,而不是使用beta版本 .

相关问题