'How to override default-filters args at route level in spring cloud gateway?

spring:
  cloud:
    gateway:
      default-filters:
        - name: AuthFilter
          args:
            enabled: true
      routes:
        - id: route
          uri: "${SERVICE1:http://localhost:8080}"
          predicates:
            - Path=/route-1/**
          filters:
            - name: AuthFilter
              args:
                enabled: false

How to override the default config args as shown above? Currently the route level args are ignored. The use case is I want to enable a filter by default but skip only for some specific routes.



Solution 1:[1]

You have to wrap the class component inside of withRouter since hooks won't work with class based components.

......................... UserPage.js .........................

import React, { Component } from 'react'
import {getUser} from '../../Api/Users-axios'
import ViewUserComp from '../ViewUserComp/ViewUserComp'
import {withRouter} from 'react-router'


export class UserPage extends Component {
 state = {
   user:{}
}
componentDidMount = () => {
    console.log(this.props)     
    const id = this.props.match.params.id; // try this one
    console.log('my id:' );
    console.log(id);
    getUser(id).then(response => {
        this.setState({
            user: response.data
        });
    })
        .catch(error => {
            alert('error');
        });
}

render() {
    return (
    <div>
        <h2>User Page</h2>
        <ViewUserComp user={this.state.user} />     
    </div>
    )
  }
 }
 export default withRouter(UserPage); // wrap it 

Solution 2:[2]

In hook, Use useParams(). Example like below.

import {useParams} from 'react-router-dom';

let { id } = useParams();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nausif Momin
Solution 2 Jai Kumaresh