首页 文章

@ angular / router没有使用参数正确渲染路由

提问于
浏览
1

我正在使用:
"@angular/core":"2.0.0-rc.1"
"@angular/router":"2.0.0-rc.1"

我正在尝试为我的主页设置多个参数,我的路线是

@Routes([
    {path: '/', component: HomeComponent},
    {path: '/:mode', component: HomeComponent},
    {path: '/:mode/:email', component: HomeComponent}
]);

当我访问http://localhost:2368/test它工作,我得到RouteParams.params.mode == 'test'但是,当我尝试通过访问http://localhost:2368/test/email添加第二个参数时,我得到:
GET http://localhost:2368/test/js/app.js 404(未找到)
浏览器正在尝试从test / js url加载app.js,这显然不存在,因为测试被认为是我的第一个参数 .

我遇到的另一个问题是,当我尝试添加一个真实的电子邮件地址作为我得到的参数时:
不能GET /test@email.com

任何帮助将非常感激 .

EDIT:
由于我的webpack配置使用相对路径导致的404错误 .
但我仍然无法使用两个路由器参数运行url

1 回答

  • 0

    我添加了标有箭头的两条线,现在可以使用了 .

    bootstrap(App, [
        HTTP_PROVIDERS,
        ROUTER_PROVIDERS,
        provide(APP_BASE_HREF, { useValue: "/" }), <-------- Added
        provide(LocationStrategy, { useClass: HashLocationStrategy }) <-------- Added
        ]).catch(err => console.error(err));
    

    感谢GünterZöchbauer的支持

相关问题