我有类似的路线
/: Login
/A: A Component
/:[dynamic] : B Component
现在我使用如下代码,但现在每次加载组件 B 时,即使我也传递了“Exact”关键字。
<Route exact path="/">
<LoginComponent />
</Route>
<Route exact path="/:dynamic" component="Dynamic' />
<Route exact path="/A" component="A" />
答案 0 :(得分:1)
发生这种情况是因为路由器无法区分动态值或“A”或“”。
据我所知,如果不为 B 组件制作另一条路线,您将无法解决它,例如 package org.example;
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(Stage stage) {
String imageUrl = "https://images.freeimages.com/images/large-previews/2e9/fisherman-in-the-lighthouse-1496152.jpg";
Image image = new Image(imageUrl);
ImageView imageView = new ImageView(image);
imageView.setPreserveRatio(true);
CustomImagePane customImagePane = new CustomImagePane(imageView);
ScrollPane scrollPane = new ScrollPane(customImagePane);
scrollPane.setFitToWidth(true);
stage.setScene(new Scene(scrollPane, 1300, 600));
stage.show();
}
/**
* A simplified example how your custom control could look like.
*/
public class CustomImagePane extends Region {
private final ObjectProperty<ImageView> imageView = new SimpleObjectProperty<>();
public CustomImagePane(ImageView imageView) {
this.imageView.addListener((observable, oldValue, newValue) -> {
if (oldValue != null)
getChildren().remove(oldValue);
if (newValue != null)
getChildren().add(newValue);
});
this.imageView.set(imageView);
}
@Override
protected void layoutChildren() {
ImageView imageView = getImageView();
if (imageView != null) {
imageView.setFitWidth(getWidth());
imageView.setFitHeight(0);
layoutInArea(imageView, 0, 0, getWidth(), getHeight(), 0, HPos.CENTER, VPos.CENTER);
}
super.layoutChildren();
}
public ImageView getImageView() {
return imageView.get();
}
public ObjectProperty<ImageView> imageViewProperty() {
return imageView;
}
public void setImageView(ImageView imageView) {
this.imageView.set(imageView);
}
}
public static void main(String[] args) {
launch();
}
}