Flutter/GoRouter
[Flutter] go_router - 2 : 초기 페이지 설정
주톨
2024. 1. 11. 13:17
728x90
* 해당 글은 go_router 13.0.1 버전으로 설명되어 있습니다.
* 버전이 업데이트되면서 바뀌는 사항은 하단에 업데이트되어 있습니다.
final router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) {
return APage();
},
),
],
);
go_router 1번 글에서 path가 ' / ' 경우에는 초기 페이지로 설정되어 앱을 실행시키면 해당 페이지가 빌드된다고 했습니다.
final router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) {
return APage();
},
),
GoRoute(
path: '/b',
builder: (context, state) {
return BPage();
},
),
],
);
그래서 ' /b ' 가 path인 BPage()를 설정해 두고 앱을 실행시켜도 APage()가 빌드되게 됩니다.
final router = GoRouter(
initialLocation: '/b',
routes: [
GoRoute(
path: '/',
builder: (context, state) {
return APage();
},
),
GoRoute(
path: '/b',
builder: (context, state) {
return BPage();
},
),
],
);
하지만 GoRouter 클래스에 initialLocation으로 '/b' path를 설정해 두면 말 그대로 초기 페이지를 '/b'인 path로 설정이 가능합니다.
앱을 실행시키면 BPage가 빌드되게 됩니다.