@@ -534,7 +534,19 @@ protected override void OnParametersSet()
534534 TabStyle = TabStyle . Default ;
535535 }
536536
537- AddTabByUrl ( ) ;
537+ if ( ClickTabToNavigation )
538+ {
539+ if ( ! HandlerNavigation )
540+ {
541+ HandlerNavigation = true ;
542+ Navigator . LocationChanged += Navigator_LocationChanged ;
543+ }
544+ AddTabByUrl ( ) ;
545+ }
546+ else
547+ {
548+ RemoveLocationChanged ( ) ;
549+ }
538550 }
539551
540552 /// <summary>
@@ -569,6 +581,22 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
569581 /// <returns></returns>
570582 protected override Task InvokeInitAsync ( ) => InvokeVoidAsync ( "init" , Id , Interop , nameof ( DragItemCallback ) ) ;
571583
584+ private void RemoveLocationChanged ( )
585+ {
586+ if ( HandlerNavigation )
587+ {
588+ Navigator . LocationChanged -= Navigator_LocationChanged ;
589+ HandlerNavigation = false ;
590+ }
591+ }
592+
593+ private void Navigator_LocationChanged ( object ? sender , Microsoft . AspNetCore . Components . Routing . LocationChangedEventArgs e )
594+ {
595+ AddTabByUrl ( ) ;
596+ InvokeUpdate = true ;
597+ StateHasChanged ( ) ;
598+ }
599+
572600 private void AddTabByUrl ( )
573601 {
574602 var requestUrl = Navigator . ToBaseRelativePath ( Navigator . Uri ) ;
@@ -595,12 +623,23 @@ private void AddTabByUrl()
595623
596624 private bool ShouldShowExtendButtons ( ) => ShowExtendButtons && ( Placement == Placement . Top || Placement == Placement . Bottom ) ;
597625
626+ /// <summary>
627+ /// 点击 TabItem 时回调此方法
628+ /// </summary>
598629 private async Task OnClickTabItem ( TabItem item )
599630 {
600631 if ( OnClickTabItemAsync != null )
601632 {
602633 await OnClickTabItemAsync ( item ) ;
603634 }
635+
636+ if ( ! ClickTabToNavigation )
637+ {
638+ TabItems . ForEach ( i => i . SetActive ( false ) ) ;
639+ item . SetActive ( true ) ;
640+ InvokeUpdate = true ;
641+ StateHasChanged ( ) ;
642+ }
604643 }
605644
606645 /// <summary>
@@ -1188,6 +1227,7 @@ protected override async ValueTask DisposeAsync(bool disposing)
11881227
11891228 if ( disposing )
11901229 {
1230+ RemoveLocationChanged ( ) ;
11911231 ErrorLogger ? . UnRegister ( this ) ;
11921232 }
11931233 }
0 commit comments