What does 'as' mean when importing a module?
The statement
import {
BrowserRouter as Router,
Route,
Link
} from 'react-router-dom'
selectively imports BrowserRouter
, Route
and Link
from react-router-dom
. The as Router
statement makes BrowserRouter
available under the name Router
(instead of BrowserRouter
). The names of Route
and Link
are not changed.
It is equivalent to:
const Router = require("react-router-dom").BrowserRouter;
const Route = require("react-router-dom").Route;
const Link = require("react-router-dom").Link;
No it is not at all like that! It's a harmony feature that was added to the Import/Export functionality.
It's the same as this:
let tmp = require("react-router-dom")
let Router = tmp.BrowserRouter
let Route = tmp.Route
let Link = tmp.Link
Or simply:
const {BrowserRouter: Router, Route, Link} = require("react-router-dom")