6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Flutter] Flutter WebでURLが遷移時に変わるようにする方法

Posted at

Navigate with named routesを使う

下記のようにroutes、initialRouteを使用するように変更して

MaterialApp(
  initialRoute: '/',
  routes: {
    '/': (context) => FirstPage(),
    '/second': (context) => SecondPage(),
  },
);

下記のようにpushNamedを利用して遷移することでURLが変わるようになるようです。

onPressed: () {
  Navigator.pushNamed(context, '/second');
}

Navigate with named routesで書き換えてみた

以前書いた[Flutter] 既存のFlutterのコードをFlutter Webで動かしてみたNavigate with named routesで書き換えてみました。

navigate-with-named-routes.gif
ちゃんとURLが変わるようになりました!

6
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?