Angular2 router.navigate refresh page

前端 未结 5 1841
终归单人心
终归单人心 2020-11-29 09:42

This is how the routes and component look like:

routes.config

export const routes: RouterConfig = [
   { path: \'users\'         


        
5条回答
  •  感动是毒
    2020-11-29 10:37

    This covers an AngularJS/Angular hybrid situation. I'm adding the answer because this question is one of the top results when you google angular router page reload issues. Hopefully it'll save somebody else time.

    In my case I had a very simple Angular 2 (actually 5) route configuration that mostly worked except for one case where a link from one route to another would inexplicably cause a page reload. I had checked for all the usual suspects, form, submit button, etc.

    It turned out that somewhere in an AngularJS component that was displayed at the time the link was clicked, there was an ng-include. The documentation warns about this for a reason I guess. Reshuffled the template so the ng-include could be changed to a templateUrl and all was well.

提交回复
热议问题