$options = ['fragment' => 'feedback'];
$url = Url::fromRoute('entity.node.canonical', ['node' => 22], $options);
$options = ['query' => ['animal' => 'dog', 'color' => 'black']];
$url = Url::fromRoute('entity.node.canonical', ['node' => 42], $options);
So first would give you this result
/node/22#feedback
and the second would be
/node/22?animal=dog&color=black