简体   繁体   English

Angular2:相同的URL路由导致页面刷新

[英]Angular2: Same url routing cause page refresh

This is part of my app NgModule: 这是我的应用程序NgModule的一部分:

@NgModule({
    imports: [
        RouterModule.forRoot([
            { path: '', component: testComponent },
            { path: 'test', component: anotherTestComponent }
        ], { useHash: true })

That is the only place where i declare my routing. 那是我声明路由的唯一地方。 I'm encountering this problem: starting from root ( /#/ ) i go first to "test" ( /#/test ) and then move back to root. 我遇到了这个问题:从root( /#/ )开始,我先去“测试”/#/test ),然后再回到root。 Here, if i click enter on address bar (with the root path), my whole app is reloaded. 在这里,如果我单击地址栏上的Enter(具有根路径),则会重新加载我的整个应用程序。 I get the same if i go to "test" first and then re-enter the "test" path on the address bar. 如果我先去“测试” ,然后在地址栏上重新输入“测试”路径,我会得到相同的结果。 I didn't test router-link within my app. 我没有在我的应用程序中测试路由器链接。

This is how the browser works, when you hit enter on the address bar it triggers a page refresh. 这是浏览器的工作方式,当您在地址栏上按Enter时,它会触发页面刷新。

To navigate through a Single Page App you use routes/links inside the app, not hitting enter on the address bar. 要浏览单页应用,请使用应用内的路由/链接,而不要在地址栏上按Enter。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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